question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
I'm using a while loop with getc() to read from a file handle and it works fine. Now I'm adding support for pipes.
My problem is that while x0A, X0D, and x0A0D pass just fine, any cases of x0D0A get reduced to just x0A. Also x1A seems to stop the process entirely when encountered.
I'm piping in the output of tar, a... |
You will need tofopenwith a binary mode. I'm not sure if you can usefreopenonstdin, but give it a try:
```
freopen(NULL, "rb", stdin);
```
|
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about programming within the scope defined in thehelp center.Closed10 years ago.Improve this question
Is there a replacement of \n in C? Can I jump to next line without using \n? I ca... |
You can useputs("A"); puts("B");.
|
This question already has answers here:Finding current executable's path without /proc/self/exe(15 answers)Programmatically retrieving the absolute path of an OS X command-line app(7 answers)Closed10 years ago.
Exactly likeHow do I find the location of the executable in C?but for Mac OS X. I am aware that argv[0] pro... |
Mac OS X implements the functions:
```
int _NSGetExecutablePath(char * buf, uint32_t * length);
int * _NSGetArgc(void);
char *** _NSGetArgv(void);
```
The first of these is probably what you want here. The other two are interesting as well, though!
|
This question already has answers here:How to find the size of an array (from a pointer pointing to the first element array)?(17 answers)Closed10 years ago.
out put is always 8! I am wondering where this number comes from and how can I get the correct size of the size of the array which is 6?
```
#include <stdlib.h>... |
You can not calculate the size of the int array when all you've got is an int pointer. You will always get pointer size.
You can possibly try this(Not sure if that is a good idea):-
```
#define arrSz(a) (sizeof(a)/sizeof(*a))
```
|
If I have some thing like:
```
printf("\nEnter 2 numbers: \n");
scanf(" %d %d", &a, &b);
add (a,b)
int a,b;
{
printf ("%d", a+b);
}
```
Then want to run the block again, but with new variables of "nothing" like when the first printf statement is entered. Any suggestions?
|
First of all avoid usingK&RC syntax
```
/* Your function
add (a,b)
int a,b;
{
printf ("Sum = %d\n", a+b);
}
*/
/* Use following style*/
void add (int a,int b)
{
printf ("Sum = %d\n", a+b);
}
int main()
{
int i,a,b; // Declare variables
int n=5; // Call it say n=5 times
for(i=0;i<n;i++) //Use a for loop to ... |
With OpenSSL 0.9.8 I have set a callback using the SSL_CTX_set_cert_verify_callback
function. However in the callback how can I get access to the target domain of the
OpenSSL connection so I can match the target domain with the certificate domain.
Thanks
|
Theargvalue that you pass toSSL_CTX_set_cert_verify_callback()will be passed to your callback function when it is called. You can use this to pass a pointer to some data structure that contains the domain.
|
I am having a code, which contains
```
bool fn()
{
...
//all the following are boolean functions.
return isTrue()
&&isMsgReceived()
&&isMsgSent();
}
```
The problem is that each of the return boolean functions are themselves quite lengthy and takes much computation. Actually, there is no point in check... |
&&already does that for you. IfisTrue()returnsfalse, the next two functions are not even evaluated.
It therefore makes sense to put the least expensive function first in a chain of&&s.
|
I would like to know if user is root, without minding if that user is using a fakeroot-like tool or not.
I tried the functionsgetuid(),geteuid()andgetlogin(), but when I launchfakerootcommand each of these sends my own account information instead ofroot.
For this code:
```
printf("%d %d %s\n", getuid(), geteuid(), ... |
It looks as if your binary (busybox) is compiled against a staticlibc.fakerootuses dynamic library preloading to intercept and replace calls to variouslibcfunctions, but this only works if your binary is dynamically linked tolibc. If it is statically linked, the function calls are bound to the real calls inside the bi... |
This question already has answers here:Turbo C++: Why does printf print expected values, when no variables are passed to it?(5 answers)Closed10 years ago.
```
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=11;
clrscr();
printf("%d");
getch();
}
```
Output=11
How the output is 11 even I am not mentione... |
The 11 is on the stack because of thebvariable, and yourprintf()function is looking on the stack for a value on the stack because that's where variables get passed.
If you add ac=47, you'll probably get 47. But this is undefined behavior.
|
This question already has answers here:BigInteger in C?(4 answers)Closed10 years ago.
I want a variable to represent the number600851475143in C but this value is larger than the maximum value of long i.e2147483647.What data type should I use?
|
Use integer typelong long.It is good for at least the range -9223372036854775807 <= x <= +9223372036854775807.
```
#include <stdio.h>
int main(int argc, char *argv[]) {
long long big = 600851475143;
printf("%lld\n", big); // prints 600851475143
return 0;
}
```
Alternatively, one could useint64_toruint64_t- ... |
I have created the following program to findfactorialfactors, but I am not able to understand why the value ofibecomes negative after a few iterations.
```
#include <stdio.h>
int main()
{
int a,b,i;
printf("enter the number: ");
scanf("%d", &a);
printf("entered value is %d\n", a);
for(i = 1; i... |
Fix:
printf("a = %d, i = %d, modulo = %d\n", b);
to
printf("a = %d, i = %d, modulo = %d\n", a, i, b);
Also, your program doesn't findfactorial!
```
b =1;
for(i = 1; i <= a; i++)
b*=i;
printf(" Factorial for a = %d \n", b);
```
|
Say I have these 8 bit chars:
```
01111111 00011100 01101111
```
I want to omit the leading 0 and append the bits from char before like so:
```
11111110 01110011 01111000
```
*note that the last char has been padded with zeros.
Any advice on how to do this would be much appreciated. cheers.
|
Shift the first char up 1:
```
num[0] << 1;
```
This will turn01111111into11111110. Now you need to OR the LSB with the MSB of the next char. To do that you need a shifted copy of the next char:
```
char copy = num[1] >> 7;
```
This would turn01110011into00000000, since it's high bit was 0. You can now OR the t... |
I want to compile this code:
```
#include <SDL.h>
int main(int argc, char* argv[]) {
return 0;
}
```
But it can't be linked:Error 1 error LNK1561: entry point must be defined
There is some strange code in this library:http://hg.libsdl.org/SDL/file/75726efbf679/include/SDL_main.h
```
#define main SDL_main
`... |
According tothis threadon Dream.In.Code:
Right click on project name -> Properties -> Expand Linker tab -> System -> SubSystem: make sure that it isConsole (/SUBSYSTEM:CONSOLE)
Alternatively, if you want to hide the console window or aredebugging a multithreaded application, you should set the SubSystem toWindow (/S... |
I have read that the type of string literal is char[n+1], where n is the length.The storage of string literals is an implementation issue.But still it must be unique at an instant.
```
printf
("%u\t %s\t %d\t %c\t %f\t %e\t %x\t %p\t",
&"XY",&"XY",&"XY",&"XY",&"XY",&"XY",&"XY",&"XY");
```
The output of this co... |
You cannot pass values of the wrong type (a type that doesn't match what the formatting specifier says is expected) and not get undefined behavior.
For instance, it's quite possible that adoublewhich is what%fexpects isbiggerthan a pointer (which is what you're actually) passing, thus leading to a mis-match between t... |
So returning0in a function(Not main)meansfalseand returning1or anything but0meanssuccess.
Why in the main() function do we put0, meaning there were no errors when1in other functions mean it ran successfully, thanks.
|
0and1(or any non-zero number) convert to the boolean valuesfalseandtruein a context where a conversion toboolhappens, e.g. inif(here) .... This is usedwithinyour program.
The return value frommainis used in a different way, it is returned to the shell that called the program. In the shell's context the value is inter... |
This question already has answers here:How can I multiply and divide using only bit shifting and adding?(15 answers)Closed10 years ago.
How can I perform multiplication by 36 using bit-shifting? Isn't it only possible to multiply by powers of 2? For example:
```
unsigned x = 4; // binary 00000000 00000000 00000000... |
You can't multiply by a non-power of 2 by bit shifting alone.
But you can break it down using addition and multiplication:
```
x * 36 = x * (32 + 4)
= (x * 32) + (x * 4)
```
Since32and4are powers of2(2^5and2^2respectively), you can perform those as separate shifts and add the results.
|
```
int main()
{
char a = 'P';
char b = 0x80;
printf("a>b %s\n",a>b ? "true":"false");
return 0;
}
```
Why does it evaluates to true?
|
On your system,charis signed. It is also eight bits, so0x80overflows what a signed 8-bit integer can represent. The resulting value is -128. SincePis some positive value, it is greater than -128.
C permits thechartype to be signed or unsigned. This is a special (annoying) property, unlike other integer types such asi... |
I am trying to assign certain members of a 2 dim array. Not able to get following code to work. Help would appreciated very very much.
```
int myArray[5][5] = {[1][1]{1},[2][2]{2},[3][3]{3},[4][4]{4}};
main()
{
printf("%d %d\n", myArray[1][1], myArray[4][4]);
}
```
|
The way you are initializing the array
```
int myArray[5][5] = {[1][1]{1},[2][2]{2},[3][3]{3},[4][4]{4}};
```
is wrong. If you are interested in designator then initialize it as follows
```
int myArray[5][5] = {[1][1] = 1,[2][2] = 2,[3][3] = 3,[4][4] = 4};
```
|
I have been trying to write a function which gives the index of rows and columns whoses element is 0. I tried using a function
```
void make_zero(int matrix[][],int row,int col)
{
int row, col;
int i,j;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(matrix[i][j]==0){
... |
Try this
```
void make_zero(int row, int col, int matrix[row][col])
{
int i,j;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
if(matrix[i][j]==0)
printf("%d %d\n",i,j);
}
}
```
|
Specifically how do you generate machine-generated header files which usually have the following comment at the top /* DO NOT EDIT THIS FILE - it is machine generated */? Could someone provide an example?
|
You need to edit the file from which the header was automatically generated, and then re-generate a new header, otherwise if you modify the generated header your changes will be over-written next time a new header is generated.
Without further information it's not possible to know how your headers are generated - it ... |
Say I have these 8 bit chars:
```
01111111 00011100 01101111
```
I want to omit the leading 0 and append the bits from char before like so:
```
11111110 01110011 01111000
```
*note that the last char has been padded with zeros.
Any advice on how to do this would be much appreciated. cheers.
|
Shift the first char up 1:
```
num[0] << 1;
```
This will turn01111111into11111110. Now you need to OR the LSB with the MSB of the next char. To do that you need a shifted copy of the next char:
```
char copy = num[1] >> 7;
```
This would turn01110011into00000000, since it's high bit was 0. You can now OR the t... |
I want to compile this code:
```
#include <SDL.h>
int main(int argc, char* argv[]) {
return 0;
}
```
But it can't be linked:Error 1 error LNK1561: entry point must be defined
There is some strange code in this library:http://hg.libsdl.org/SDL/file/75726efbf679/include/SDL_main.h
```
#define main SDL_main
`... |
According tothis threadon Dream.In.Code:
Right click on project name -> Properties -> Expand Linker tab -> System -> SubSystem: make sure that it isConsole (/SUBSYSTEM:CONSOLE)
Alternatively, if you want to hide the console window or aredebugging a multithreaded application, you should set the SubSystem toWindow (/S... |
I have read that the type of string literal is char[n+1], where n is the length.The storage of string literals is an implementation issue.But still it must be unique at an instant.
```
printf
("%u\t %s\t %d\t %c\t %f\t %e\t %x\t %p\t",
&"XY",&"XY",&"XY",&"XY",&"XY",&"XY",&"XY",&"XY");
```
The output of this co... |
You cannot pass values of the wrong type (a type that doesn't match what the formatting specifier says is expected) and not get undefined behavior.
For instance, it's quite possible that adoublewhich is what%fexpects isbiggerthan a pointer (which is what you're actually) passing, thus leading to a mis-match between t... |
So returning0in a function(Not main)meansfalseand returning1or anything but0meanssuccess.
Why in the main() function do we put0, meaning there were no errors when1in other functions mean it ran successfully, thanks.
|
0and1(or any non-zero number) convert to the boolean valuesfalseandtruein a context where a conversion toboolhappens, e.g. inif(here) .... This is usedwithinyour program.
The return value frommainis used in a different way, it is returned to the shell that called the program. In the shell's context the value is inter... |
This question already has answers here:How can I multiply and divide using only bit shifting and adding?(15 answers)Closed10 years ago.
How can I perform multiplication by 36 using bit-shifting? Isn't it only possible to multiply by powers of 2? For example:
```
unsigned x = 4; // binary 00000000 00000000 00000000... |
You can't multiply by a non-power of 2 by bit shifting alone.
But you can break it down using addition and multiplication:
```
x * 36 = x * (32 + 4)
= (x * 32) + (x * 4)
```
Since32and4are powers of2(2^5and2^2respectively), you can perform those as separate shifts and add the results.
|
What is the value of putchar(c) outside loop?
```
main()
{
int c;
while (c = getchar() != EOF) {
printf("printf c_inloop :%d\n",c);
printf("Putchar c_inside: ");
putchar(c);
printf("\n\n");
}
putchar(c);
printf("printf c_outloop %d",c); /*outside loop*/
}
```
When I run the program, say ... |
When you exit the loop, the value ofcisEOF, which isn't a valid character value (that's why it's used to indicate end of file). It makes no sense to pass it toputchar.
|
I'm writing a Windows application in C and I'm trying to figure out how to retrieve metadata about files (specifically, it's the author information that I'm interested in). I've been up and downMicrosoft's list of functionsand I haven't found anything that looks like what I want.
From Google and other Stack Overflow ... |
The easiest way to do this is using the shell via theIShellFolder2::GetDetailsEx()API. This way you have access to any metadata the shell knows how to extract. There's an examplehereof using this interface to query items in the recycle bin, but the same technique applies to any folder.
|
C has the following syntax for a shorthand IF-ELSE statement
```
(integer == 5) ? (TRUE) : (FALSE);
```
I often find myself requiring only one portion (TRUE or FALSE) of the statement and use this
```
(integer == 5) ? (TRUE) : (0);
```
I was just wondering if there was a way to not include the ELSE portion of the ... |
The operator?:must return a value. If you didn't have the "else" part, what would it return when the boolean expression is false? A sensible default in some other languages may be null, but probably not for C. If you just need to do the "if" and you don't need it to return a value, then typingifis a lot easier.
|
I am not able to get error details using the PQresultErrorField API after a query execution fails. Using PQerrorMessage on the connection gives the correct error (constraint violation xxx_pk etc etc) and PQresultStatus shows FATAL_ERROR.
However, when I use the API PQresultErrorField(result, PG_DIAG_SQLSTATE)), I get... |
It's supposed to return NULL only when it's not applicable.
That simple test works for me:
```
PGresult* res = PQexec(conn, "SELECT * FROM foobar");
if (res) {
if (PQresultStatus(res) == PGRES_FATAL_ERROR) {
char* p = PQresultErrorField(res, PG_DIAG_SQLSTATE);
if (p) {
printf("sqlstate=%s\n"... |
I'm trying to install SDL on MinGW.
I've downloaded SDL fromhere(theSDL2-devel-2.0.0-mingw.tar.gzlink), then copied the contents ofSDL2-2.0.0/x86_64-w64-mingw32/{bin,include,lib}into the matching directories in my MinGW installation.
When I try to compile any file that contains#include ‹SDL2/SDL.h›usinggcc test.c -l... |
SDL2-devel-2.0.0-mingw.tar.gzcontains both 32-bit libraries (i686-w64-mingw32directory) and 64-bit libraries (x86_64-w64-mingw32directory).
The error was caused by using a 64-bit version of the library with a 32-bit compiler.
|
This question already has answers here:warning in extern declaration(4 answers)Closed10 years ago.
When i compile and run the following code, codeblocks(windows 7 64-bit) issues a couple of warnings:-
```
#include<stdio.h>
#include<stdlib.h>
extern int i=10; //Warning
int main()
{
extern int i;
... |
Taken the help fromhere
Thats a valid syntax. The problem is thatexternkeyword is redundant because the object is initialised in the same compilation unit.
|
Closed. This question needs to be morefocused. It is not currently accepting answers.Want to improve this question?Update the question so it focuses on one problem only byediting this post.Closed10 years ago.Improve this question
Just out of curiosity, i wanted to know why are my compiled.Cfiles(approx 2-5 kb) are sm... |
You compiler source file is just the generated code from the actual source file and not much else. An executable have been linked with other object files and libraries, needed for all external functions and variables you need. That of course makes the executable much bigger as it contains much more code.
|
```
void qkSort (int *arr,int size)
{
if (size>1)
{
int p = partition(arr,size);
qkSort(arr,p);
qkSort(arr+p+1,size-(p-1));
}
return;
}
int partition(int *arr,int size)
{
int i,j,pivot,temp;
pivot = size-1;
for(i=0,j=-1;i<size-1;++i)
{
if (arr[i]<arr[pivot])
... |
Please refer to:http://p2p.wrox.com/visual-c/66347-quick-sort-c-code.html
This example should help you get started.
|
How can i store128or256bit data types(ints and floats) without using any data structures(like arrays and others) and external libraries on a 64-bit machine.I am using codeblocks.
|
You cannot do this using the C language as laid out in the standard. However, depending on your compiler and architecture, you may have compiler-specific support for larger integer sizes. For instance, GCC supplies limitedsupportfor 128-bit integers, which you can use like so:
```
__int128 foo; //foo is a 128-bit sig... |
I have the following code snippet which reads the pixel value in hex format.
```
Uint32* MyPixel = pixels + ( (iH-1) + image->w ) + iW;
printf("\npixelvalue is is : %x",*MyPixel);
```
How can I reassign a new hex value into the *MyPixel cause I tried this does not work.
```
*MyPixel = "00FF00";
```
|
"00FF00"is a string literal. You need a hex integer literal:
```
*MyPixel = 0x00FF00;
```
Prefix0xtells the compiler that the rest of the numeric literal needs to be interpreted as a numeric hex constant.
|
```
#include<stdio.h>
#include<conio.h>
int main()
{
char arr[]="\0";
if(printf("%s",arr))
printf("not empty");
else
printf("empty");
return 0;
}
```
Here I thought that\0will be taken as 1 byte in the array andprintfwill return 1 byte, so not empty should be printed. But output wasem... |
```
char arr[]="\0";
```
Here, thechararrayarrhas two elements, both of them are\0. When you use:
```
printf("%s",arr)
```
%sin format specifier tellsprintfto look for a string. Andprintffound it, but it stops printing after seeing the first\0, which is the first character. That's whyprintfprints nothing, becausear... |
I have about 100,000 files in a directory. I have to move all these files to another directory. There are two ways of doing it.
rename(oldfile, newfile)link(oldfile, newfile)unlink(oldfile)
Which approach is better? Are there any other better solutions?
|
Short answer:
The first solution.
Using therenamecall you only execute one system call, and it can be further optimized by the system and / or the implementation.
You also state clearly what you intend to do, which is more important than simply searching ultimate performance on a single point of your program.
The... |
I'm really getting frustrated here. Trying to implement the CRC-CCITT algorithm and I found a very nice example on an Internet site.
There is one line whose output I completely don't understand:
```
unsigned short update_crc_ccitt( unsigned short crc, char c){
[...]
short_c = 0x00ff & (unsigned short) c;
[...]
}
``... |
The character1has ASCII code 0x31 = 49. This is different from the character with ASCII code 1 (which is^A).
|
Hello I have a two dimensionalarray[8][8], the elements are filled with either1or0. So my question is: How do I convert one whole row into an unsigned integer that is 8 bits long?
I'm coding in C.
|
Like this:
```
int array[8][8]; /* this is what you have */
unsigned row0 = 0;
int i;
for( i = 0; i < 8; i++ ) row0 |= (unsigned)array[0][i] << i;
/* row0 now contains the converted number */
```
This assumes your data is least-significant-bit first.
|
What is the value of putchar(c) outside loop?
```
main()
{
int c;
while (c = getchar() != EOF) {
printf("printf c_inloop :%d\n",c);
printf("Putchar c_inside: ");
putchar(c);
printf("\n\n");
}
putchar(c);
printf("printf c_outloop %d",c); /*outside loop*/
}
```
When I run the program, say ... |
When you exit the loop, the value ofcisEOF, which isn't a valid character value (that's why it's used to indicate end of file). It makes no sense to pass it toputchar.
|
I'm writing a Windows application in C and I'm trying to figure out how to retrieve metadata about files (specifically, it's the author information that I'm interested in). I've been up and downMicrosoft's list of functionsand I haven't found anything that looks like what I want.
From Google and other Stack Overflow ... |
The easiest way to do this is using the shell via theIShellFolder2::GetDetailsEx()API. This way you have access to any metadata the shell knows how to extract. There's an examplehereof using this interface to query items in the recycle bin, but the same technique applies to any folder.
|
C has the following syntax for a shorthand IF-ELSE statement
```
(integer == 5) ? (TRUE) : (FALSE);
```
I often find myself requiring only one portion (TRUE or FALSE) of the statement and use this
```
(integer == 5) ? (TRUE) : (0);
```
I was just wondering if there was a way to not include the ELSE portion of the ... |
The operator?:must return a value. If you didn't have the "else" part, what would it return when the boolean expression is false? A sensible default in some other languages may be null, but probably not for C. If you just need to do the "if" and you don't need it to return a value, then typingifis a lot easier.
|
I have the multi-threading C application (daemon). Can I measure the CPU usage by thread into my application.
|
While this is an old question it came up as the top related hit on my own Google search. So I'll provide the answer I came up with.
Assuming you're using pthreads or a library that uses it, such as Boost libraries.
You can usepthread_getcpuclockidandclock_gettime.Man page linkspthread_getcpuclockid,clock_gettime.
H... |
Ive got function that shifts array by 1 index to right:
```
void arrayShiftRight(int array[], int size) {
int temp = array[size - 1];
for ( int i = size; i > 0; i-- ) {
array[i] = array[i - 1];
}
array[0] = array[temp];
}
```
the input is
0 1 2 3 4 5 6
the output is
5 0 1 2 3 4 5
I can't ... |
You have an off by one error, andtempis not an index, it's the stored value:
```
// i needs to start at size-1, not at size.
// Otherwise, you'd be writing past the end of the array.
for ( int i = size-1; i > 0; i-- ) {
array[i] = array[i - 1];
}
array[0] = temp;
```
|
I want to achieve the same as you would in thestringWithFormatmethod.
I was wondering if you could call in another constant inside my#define?
e.g.[NSString stringWithFormat:@"If you enjoyed %@ would you mind please reviewing it?", appName];
I want:
```
#define appName @"This App"
#define myMessage @"If you enjoye... |
```
#import <Foundation/Foundation.h>
#define appName @"This App"
#define myMessage @"If you enjoyed " appName @" would you mind please reviewing it?"
int main( void )
{
@autoreleasepool
{
NSLog( myMessage );
}
return 0;
}
```
|
When i read tty_io.c, i see this definition. What does this __releases() mean?
```
void tty_write_unlock(struct tty_struct *tty)
__releases(&tty->atomic_write_lock)
{
mutex_unlock(&tty->atomic_write_lock);
wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
}
```
|
Apparently__releasesand__acquiresare two macros defined in Linux's compiler.h header which are used with theSparsestatic checker to count locks released and acquired (to make sure that they are balanced).
|
I am working in Visual Studio 2010. I am creating a simple application which shows the icon in the tray(taskbar). the problem i am facing is the application is shown in the tray(taskbar), but its icon is not shown. My code is given below
```
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
n... |
```
nid.uFlags = NIF_MESSAGE NIF_ICON NIF_TIP;
```
should be
```
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
```
Also,
```
MAKEINTRESOURCE(IDI_ICON2)
```
should be
```
IDI_ICON2
```
if this is the name of the icon
|
The program doesn't output anything currently. The program is meant to take an integer command line value and then print "Test" that number of times using a recursive printing function. I'm new to C and can't figure out why the program isn't working, I'm not getting any compilation errors. (Still working on getting fa... |
Because you are not passing an int:
```
i = atoi(argv[0]);
^
argument 0 is name of executable
```
may be your need:
```
i = atoi(argv[1]);
```
|
I was doing a bitshift operation of an int and was surprised that it didn't come out as expected.
```
int i, res;
i = 0x80000000;
res = i>>1; //results in 0xc0000000
res = (unsigned int) i>>1; //results in 0x40000000
```
how is it possible that a shift of a bit in an integer does only work to the 31st... |
What you are seeing is probablyarithmetic bit shift.
when shifting to the right, the leftmost bit (usually the sign bit in
signed integer representations) is replicated to fill in all the
vacant positions (this is a kind of sign extension).
TheC99 standard6.5.7§5 says:
The result of E1 >> E2 is E1 right-shifted... |
Using libjpeg (or libjpeg-turbo) to do JPEG encoding, I was wondering if there is any improvements providing multiple scanlines at once to the jpeg_write_scanlines function.
I did some tests on 720x288 images, but I only get 0,5% increase when processing the whole image at once.
I guess this increase is just due to t... |
JPEG has a minimum height of a row, called MCU height. It is 8 lines in images without subsampling (4:4:4 mode) or 16 lines if chroma is subsampled (4:2:0 mode).
If you feed libjpeg these 8 or 16 lines it will be able to process the whole row in one go. Otherwise it'll need to do extra bookkeeping or buffering.
Writ... |
Edited....I got direction from @pablo1977 where to code and compile the codes online. Thanks.
Sorry I got to edit this question to prevent further down vote.
|
Try this
time(..) function with NULL input argument, will return the number of seconds from January 1, 1970
time(time_t*) type
So input argument 0 is consider as NULL.
But 1 will generate error.
Input must be a time_t* type
```
#include <stdio.h>
#include <time.h>
int main ()
{
time_t seconds;
seconds = time ... |
I just don't understand why this Yes/No loop will not work. Any suggestions? Given the input is "Y". I just want it to run the loop, then ask for Y or N again. If Y, print success, if N, print a good bye statement. What's the reason?
```
int main(){
char answer;
printf("\nWould you like to play? Enter Y o... |
Change the secondscanfto:
```
scanf(" %c", &answer);
// ^
```
The problem is, when you enter Y and press ENTER, the new line is still in the input buffer, adding a space before%ccould consume it.
|
I have a structure with a 2d array. I'm passing a pointer to this structure to a function, where I need to edit the 2d array. I am struggling to find the correct syntax to reference the 2d array from within my function.
```
#define TG_WIDTH 10
#define TG_HEIGHT 20
typedef enum {
BLOCK_T = 0,
BLOCK_LINE,
B... |
ChangeTG_WIDTHtoTG_HEIGHT:
```
block_t (*g)[TG_HEIGHT] = sp->grid;
```
|
I need to convert an array of hex numbers to a string, such that it can be passed to a C function (using Inline::C) as an unsigned char*, which then can be put into an array of bytes:
```
my @hex_vals = (0x06, 0x0D, 0x04, 0x16, 0x19, 0x0);
```
On the C side, function looks like this:
```
void takeMessage(unsigned c... |
```
takeMessage(pack 'C*', @hex_vals)
```
And on the XS side, I'd use
```
void takeMessage(SV* message_sv)
{
STRLEN len;
unsigned char* message_buf = (unsigned char*)SvPVbyte(message_sv, len);
unsigned char stuff[1088];
if (len > 1088)
croak("...");
Copy(message_buf, stuff, len, unsigne... |
I have a file with data written as in an example:
```
text1 1542 542 6325 6523 3513 323
text2 1232 354 5412 2225 2653 312
text3 ....
...
```
I want my program to read and print only selected data, i.e. only 3rd and 4th column, every second row. So I need to skip the string "text1" at the beginning, but a... |
scanf with * modifier skips that part of data, so in your case do
```
fscanf(FilePointer,"%s %*d %*d %d %d", &col3, &col4);
```
it will read columns 3 and 4 as you wanted to.
Then you print them with regular
```
printf("%d %d\n", col3, col4);
```
|
VariablesT,max_grayandqtd_pxare always greater than 0, andnumeros_pxis anunsigned charvector that stores values from 0-255.
If it's possible, please explain why, because it seems to work fine here in CodeBlocks, but it doesn't make sense for me, because they are from different types: one isunsigned charand the other o... |
Yes you can assign char to int, because char is 8 bit wide, integer is 32 (depends on the architecture but on PCs, and 32 bit ARMs, it is 32 bit wide. 16 bit on some chips)
What you can not do is the oppsite as obviously you might loose data.
*In your code this is bad : *numeros_px[i]=max_gray;asmax_greyis 32 bits an... |
This question already has answers here:How to zero out new memory after realloc(5 answers)Closed10 years ago.
How to reallocate content on bigger storage but that the rest of content be zero ?
I have at the moment like
```
void* oldContent;
size_t oldContentSize;
size_t newBufferSize;
realloc(oldContent, newBufferS... |
```
void*newContent;
newContent = realloc(oldContent,newBufferSize);
memset(newContent + oldContentSize, 0, newBufferSize - oldContentSize);
```
|
I am writing a project in C using GCC 4.8 and I would like to see all the warnings (hoping to eliminate them) but the problem is I am #including some old, not maintained library which gives me huge wall of warnings in reaction to -Wall option. There is no way I fix those and I just want to ignore it focusing on code I... |
Update your makefile so that you have a different gcc -Wxxx line for different files (or groups of files)
```
result.exe : xxx.o yyy.o
gcc -o result.exe xxx.o yyy.o
xxx.o : xxx.c
gcc -Wall xxx.c
yyy.o : yyy.c
gcc -W yyy.c
```
|
I'm a week into an intro programming class, and I'm having trouble with fixing what's supposed to be a relatively simple code. I keep getting an invalid type argument of unary '*' error.
```
#include <stdio.h>
#define PI 3.14159;
int main()
{
float r;
float area;
scanf("%f", &r);
area = PI * r * r;
pr... |
```
#define PI 3.14159;
^
```
Drop the semicolon. Leaving it in, the code will expand to:
```
area = 3.14159; * r * r;
```
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed10 years ago.Improve this question
Please help, this is a possible interview question I'm going to face tomarrow:
find the output of
```
ma... |
The key here is that fork() will return a different value to the original process than it does to the new, child process. In particular, it returns 0 to the child, and the pid of the child to the original. From that, you can figure out the output.
(Well, you could if used puts() instead of printf(), but since you're... |
How can I use commercial at sign in Objective-C macro?
I know it is not recommended, but seems it is possible somehow? Sincelibextobjcprovides@weakify,@strongify, etc...
|
libextobjcuses preprocessor trickery to make you think it's an@command.
```
#define weakify(...) \
try {} @finally {} \
metamacro_foreach_cxt(ext_weakify_,, __weak, __VA_ARGS__)
```
Note the missing@on thetry.
So@weakifyexpands into@try {} @finally {} [injected code].
You could use the same trick, but I su... |
I have a 2 dimensional matrix:
```
char clientdata[12][128];
```
What is the best way to write the contents to a file? I need to constantly update this text file so on every write the previous data in the file is cleared.
|
Since the size of the data is fixed, one simple way of writing this entire array into a file is using the binary writing mode:
```
FILE *f = fopen("client.data", "wb");
fwrite(clientdata, sizeof(char), sizeof(clientdata), f);
fclose(f);
```
This writes out the whole 2D array at once, writing over the content of the ... |
I would like to get some infos with C about hardware:
how many CPU's I havehow many cores have each of themhow many logical cores have every core in every CPUCPU name + modelCPU speed + frequencyCPU architecture (x86, x64)
I know that on Linux-like OS I can parse/proc/cpuinfobut since its not an ordinary file, I thi... |
For Windows, you'll want theGetSystemInfofunction;Microsoft has an example. On Linux,/proc/cpuinfois perfectly "safe", whatever that means, but there's alreadyan answer to this question.
|
I am trying to use pinvoke to marshal a C structure to C#. While I am able to marshal an intptr I cannot find the syntax to marshal a double pointer. Both the int pointer and double pointer are used on the C side to alloc an array of ints or doubles.
Here is the C struct:
```
struct xyz
{
int *np; // an int... |
Check outthis description for what an IntPtr is. Have you tried using:
```
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class xyz
{
IntPtr np;
IntPtr foo;
}
```
|
I have disabled firewall, made entries in the /etc/hosts. Port is showing listening in lsof -i -P and netstat -antlp command.
```
netstat -antlp| grep 16000
tcp 0 0 192.168.1.50:16000 0.0.0.0:* LISTEN 2405/rsrtd
lsof -i -P | grep 16000
rsrtd 2405 root 3u IPv4 19628 0t0 TCP Redhat:16000 (LISTEN)
```
Also when i am ... |
Thanks All for the response.
I have figured it out the problem. Actually port was listening correct. There was very silly mistake in my program. In client program i compared the error with "!=0" in connect call that's why if even call is succeeded it is going in error condition. Also same thing i done with the bind ... |
I am quite new to C programming, but was wondering if there is a function that allows you to copy a char array into another char array starting at a particular index, other than using a for loop?
For example, I want to copy the entire contents ofsourceintobufferusing, say, element 4 ofbufferas the starting point.sour... |
Yes,memcpyis designed to copy data. The source and destination can be arbitrary locations in memory (as long as it is memory you are allowed to read/write).
In answer to your specific question:
```
memcpy(buffer+4, source, length);
```
If the source and target areas may overlap, usememmoveinstead.
```
memmove(buff... |
In a typical C program, both static variable and global variable reside on the data segment. Still the scope of static variable is limited to file. On the contrary, the global variable can be accessed from anywhere. Why does it happen, although both reside in the same memory?
|
By design.
staticat global scope is the keyword you use to mean "I want these variables limited in scope; I do not want to have to care what other modules have declared variables of the same name." The reason using this keyword does a different thing to not using it is in fact exactly the reason for its existence.
N... |
```
* glibc detected ./load: double free or corruption (!prev): ADDRESS **
```
When using glibc, how does it know that I am double-freeing? Does it keep track of everything I malloced and freed? Is it contained in metadata like how free knows how much space to free (How does free know how much to free?)
|
For each allocation, memory manager keeps some 'header' (most likely tree node or linked list). When you passed to free something that doesn't contain valid header - well, it couldn't correctly be freed. As for where this information is being kept - it's up to implementation, but usually it placed right before address... |
After running this program on C, I cannot exit from it through cmd no matter how many times I press Ctrl + Z. This program counts the number of tabs, new lines and new blanks
```
main()
{
int c, nl, nb, nt;
nl = 0;
nb = 0;
nt = 0;
while ((c == getchar()) != EOF){
if (c == '\n')
++nl;
i... |
Ctl+DisEOFinUNIX based systems.you need to press ctl+D when ever you want to stop
Ctl+ZisEOFinWindows.you need to press ctl+z when ever you want to stop.
```
while ((c == getchar()) != EOF) ==> while ((c = getchar()) != EOF)
^^ ^
```
|
Note:My question is not related tothis.
Besides the variable not being seen outside the file it is declared in,in terms of memory allocation, is there any difference between declaring this (outside of a method):
```
NSString *const kMyConstant = @"Hello World";
```
Or this:
```
static NSString *const kMyConstant =... |
In terms of memory allocation, no, there's no difference. Both variables are pointers to the same string constant, both are allocated once, and in both cases, their lifetime is the lifetime of the program.
|
Is there a better way instead ofwhile(1)in c? My concern is to wait in the code. and move further if work is done.
Like,
in some thread
```
while (cond == 0) {
// wait
}
```
From some other thread,condvariable made1, then thread can move further..
I want to remove this infinite while condition. Using sem... |
From what you describe, a condition variable seems to be the more appropriate solution. Seehere.
|
I'm new to OSX and XCode and I'm trying to statically link to a C app. I downloaded and installed libconfig and I link to the installed libconfig.a. It works great on my machine but when I run my binary on another machine I get an error that says libconfig.dylib can't be found. Naturally, I don't want to have to insta... |
I got this to work. This seems to be a libconfig build issue, maybe expected behavior but it surprised me. I was linking to libconfig.a, but it appears that libconfig.a was linking to libconfig.dylib. I reconfigure libconfig and reinstalled it.
```
./configure --disable-shared
make clean
make
make install
```
|
Receiving error: conflicting types for ‘six’ when attempting to compile.
```
void main(){
const int k = 4;
six(&k);
}
float * six(const int *x)
{
float *p = malloc(sizeof(float));
*p = (float)*x;
return p;
}
```
|
Here is what is going on.
When the compiler does not encounter a prototype for a functionbeforea call to it, it deduces the prototype from the call itself, and assumes the return type to be int. This is what it does in your example.
Later it finds the definition of the function, and it finds that the return type is ... |
I am writing a function that ask the user for input and then checks if that input is infact a positive number if not it loops until a positive number is inputed and then returns that values. This is what i have so far but when it returns im getting a weird number like 20204421.000 any help?
```
/* Checks if rate is i... |
You should usescanf("%d", &rentrate);to get an integer value."%f"is used when you want to input a floating point number.
If you want more information about howscanf()works,you can take a look in here.
|
Why does this basic code return an incorrect value? I'm relatively new to programming, and I can't understand why this basic function isn't working. I have a working version of this program, so I don't understand the issue.
```
#include <stdio.h>
int main (void)
{
int fahrenheit;
printf("Enter the temperature in de... |
printfdoes not expect a pointer to your variables likescanf, it expects the data.
Tryprintf("\n%d \n", fahrenheit);
|
I am try to build a basic linked list in C. I seem to get an error for this code:
```
typedef struct
{
char letter;
int number;
list_t *next;
}list_t;
char letters[] = {"ABCDEFGH"};
list_t openGame, ruyLopez;
openGame.letter = letters[4];
openGame.number = 4;
openGame.next = &ruyLopez;
ruyLopez.letter... |
When you are usinglist_t *nextin your code, the compiler doesn't know what to do withlist_t, as you haven't declared it yet. Try this:
```
typedef struct list {
char letter;
int number;
struct list *next;
} list;
```
As H2CO3 pointed out in the comments, using_tas an identifier suffix is not a great idea... |
In my program the user inputs the number of decimal places he requires in an output. I save this input as deci. How do I use this variabledecias a precision modifier?
Sample:
Input a number: 23.6788766
Input number of decimals: 2
Output: 23.67
|
If it is C you can do:
```
float floatnumbervalue = 42.3456;
int numberofdecimals = 2;
printf("%.*f", numberofdecimals, floatnumbervalue);
```
|
the task in this is to copy the firstncharacters from (null terminated) string2 (s2) intos1while using pointers. I know how to copy the strings from one to another, but I am having issues with eliminating the extra values. For example:
```
s1= 'This is a test'
s2 = 'A test'
after copying, I am left with:
s1 = 'a te... |
You need to somehow indicate the end of the string after the for. Spoiler:
s1pointer[i] = 0;
|
I'm looking at the example for strchr() on:http://www.cplusplus.com/reference/cstring/strchr/
Why does this correctly find the index? Intuitively it looks like it should be giving a negative index:
```
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "This is a sample string";
char * pch;
pri... |
Intuitively it looks like it should be giving a negative index:
No, becausestrchrreturns a pointer to the place where that character is found. So every timestrchrreturns non-NULL, that pointer it will be somewhere "further down" compared to the pointer where it started.
|
I would like to get some infos with C about hardware:
how many CPU's I havehow many cores have each of themhow many logical cores have every core in every CPUCPU name + modelCPU speed + frequencyCPU architecture (x86, x64)
I know that on Linux-like OS I can parse/proc/cpuinfobut since its not an ordinary file, I thi... |
For Windows, you'll want theGetSystemInfofunction;Microsoft has an example. On Linux,/proc/cpuinfois perfectly "safe", whatever that means, but there's alreadyan answer to this question.
|
I am trying to use pinvoke to marshal a C structure to C#. While I am able to marshal an intptr I cannot find the syntax to marshal a double pointer. Both the int pointer and double pointer are used on the C side to alloc an array of ints or doubles.
Here is the C struct:
```
struct xyz
{
int *np; // an int... |
Check outthis description for what an IntPtr is. Have you tried using:
```
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class xyz
{
IntPtr np;
IntPtr foo;
}
```
|
I have disabled firewall, made entries in the /etc/hosts. Port is showing listening in lsof -i -P and netstat -antlp command.
```
netstat -antlp| grep 16000
tcp 0 0 192.168.1.50:16000 0.0.0.0:* LISTEN 2405/rsrtd
lsof -i -P | grep 16000
rsrtd 2405 root 3u IPv4 19628 0t0 TCP Redhat:16000 (LISTEN)
```
Also when i am ... |
Thanks All for the response.
I have figured it out the problem. Actually port was listening correct. There was very silly mistake in my program. In client program i compared the error with "!=0" in connect call that's why if even call is succeeded it is going in error condition. Also same thing i done with the bind ... |
I am quite new to C programming, but was wondering if there is a function that allows you to copy a char array into another char array starting at a particular index, other than using a for loop?
For example, I want to copy the entire contents ofsourceintobufferusing, say, element 4 ofbufferas the starting point.sour... |
Yes,memcpyis designed to copy data. The source and destination can be arbitrary locations in memory (as long as it is memory you are allowed to read/write).
In answer to your specific question:
```
memcpy(buffer+4, source, length);
```
If the source and target areas may overlap, usememmoveinstead.
```
memmove(buff... |
In a typical C program, both static variable and global variable reside on the data segment. Still the scope of static variable is limited to file. On the contrary, the global variable can be accessed from anywhere. Why does it happen, although both reside in the same memory?
|
By design.
staticat global scope is the keyword you use to mean "I want these variables limited in scope; I do not want to have to care what other modules have declared variables of the same name." The reason using this keyword does a different thing to not using it is in fact exactly the reason for its existence.
N... |
```
* glibc detected ./load: double free or corruption (!prev): ADDRESS **
```
When using glibc, how does it know that I am double-freeing? Does it keep track of everything I malloced and freed? Is it contained in metadata like how free knows how much space to free (How does free know how much to free?)
|
For each allocation, memory manager keeps some 'header' (most likely tree node or linked list). When you passed to free something that doesn't contain valid header - well, it couldn't correctly be freed. As for where this information is being kept - it's up to implementation, but usually it placed right before address... |
After running this program on C, I cannot exit from it through cmd no matter how many times I press Ctrl + Z. This program counts the number of tabs, new lines and new blanks
```
main()
{
int c, nl, nb, nt;
nl = 0;
nb = 0;
nt = 0;
while ((c == getchar()) != EOF){
if (c == '\n')
++nl;
i... |
Ctl+DisEOFinUNIX based systems.you need to press ctl+D when ever you want to stop
Ctl+ZisEOFinWindows.you need to press ctl+z when ever you want to stop.
```
while ((c == getchar()) != EOF) ==> while ((c = getchar()) != EOF)
^^ ^
```
|
Note:My question is not related tothis.
Besides the variable not being seen outside the file it is declared in,in terms of memory allocation, is there any difference between declaring this (outside of a method):
```
NSString *const kMyConstant = @"Hello World";
```
Or this:
```
static NSString *const kMyConstant =... |
In terms of memory allocation, no, there's no difference. Both variables are pointers to the same string constant, both are allocated once, and in both cases, their lifetime is the lifetime of the program.
|
Is there a better way instead ofwhile(1)in c? My concern is to wait in the code. and move further if work is done.
Like,
in some thread
```
while (cond == 0) {
// wait
}
```
From some other thread,condvariable made1, then thread can move further..
I want to remove this infinite while condition. Using sem... |
From what you describe, a condition variable seems to be the more appropriate solution. Seehere.
|
This question already has answers here:Why isn't sizeof for a struct equal to the sum of sizeof of each member?(13 answers)Closed10 years ago.
Why does the sizeof operator when used on structures always gives different number of bytes
than actually used by the structure to store the data(what i expect)?
|
FromTHISpost
This is because of structure alignment. Structure alignment refers to
the ability of the compiler to insert unused memory into a structure
so that data members are optimally aligned for better performance.
Many processors perform best when fundamental data types are stored at
byte-addresses that ... |
I'm getting"error: expected '}'"where the '^' is pointing when I compile in the following C++ source:
```
typedef enum { false, true } Boolean;
^
```
I don't get this error when I compile it as C source.
What it the reason for this? I'm stumped!
|
falseandtrueare C++ keywords, so you can't use them asenumidentifiers.
In C they are not keywords so your code will work, but if you include<stdbool.h>then it will fail to compile because that header definesfalseandtrueas macros.
Note that you probably shouldn't implement a boolean type yourself. C++ already has the... |
Sincesizeofis an operator, why can we usesizeof(something);like a function call?When is a byte not 8 bits?
A byte in this context is the same as an unsigned char, and may be larger than 8 bits
And is there a possible that byte is smaller than 8 bits?
|
Since sizeof is a operater ,why can we use sizof(something); like a function call ?
Well,+is an "operater" (sic!) too, still you can write(1 + 1)and(1) + (1)and((1) + 1)... it's just normal parenthesizing/grouping.
When byte is not 8 bits?
When you use a platform on which it isn't 8 bits.
And is there a possible t... |
While studying in detail about malloc() I came across this strange behavior.
```
int *p;
p=(int*)malloc(10.45);
p=(int*)malloc(10.45f);
p=(int*)malloc('j');
```
The program compiles with any of these statements with just a warning and returns a valid address.
What's the real result here?
|
All of those values are implicitly converted tosize_tbefore calling the function, just as if you had an explicit cast. The floating point numbers are truncated, and the'j'is interpreted as its numerical value in your character set.
|
I have a global counter variable in c projet.
It increase out of desired bounds,
but i cannot find the line of the increase.
Is there any way to hold execution on the line where this variable is aboveX?
I can get the variable memory address.
|
A few minutes of googling confirmed what I suggested in my comment:
GDB, which is the debugger for GCC, supports so-calledwatchpoints.
You can find a descriptionhere, how to set them in GDB's command line. You can toggle those watchpoints in Eclipse as well (supposedly depends on the Eclipse version you are using).T... |
howchar * (*arr)[2]andchar **array[2]are different from each other ?? if I am passingchar* strings[2]using a function then how to access the elements from both the ways mentioned in first part of question?
Please also tell other ways to access elements of pointer array also.
Thanks.
|
CDeclreports:
```
char *(*arr)[2]
declare arr as pointer to array 2 of pointer to char
```
and
```
char **arr[2]
declare arr as array 2 of pointer to pointer to char
```
It's just that the[]array declarator has higher precedence than the*pointer qualifier, so parentheses change the meaning.
|
I have an array that holds a history of values, and when adding a new value, I need to shift all previous values one position to the left, to loose the oldest value and make room for the next.
I can think of two ways of doing this, by using memmove:
```
memmove(&arr[0], &arr[1], sizeof(arr) - sizeof(*arr));
```
Or ... |
There is a faster option:
Acircular bufferwhere insert, remove and read are all O(1).
|
Let the first row be:
```
#define TAG_LEN 32
```
Now, I need to concatenate it with a literal string constant; something like that:
```
puts("Blah" [insert your answer] TAG_LEN); // I need "Blah32".
```
|
```
#define STR_NOEXPAND(tokens) # tokens
#define STR(tokens) STR_NOEXPAND(tokens)
puts("Blah" STR(TAG_LEN));
```
|
How to create a dialog without aTitle bar. I want to createmotifdialog/widget usingXtVaCreateMangedWidgetandXtVaCreateWidgetwithout a title bar and how to create the same dialog full screen?
|
I just solved the issue, here is the detail
```
m_wgMainFrm = XtVaAppInitialize(&m_pApp, ...
m_wgMainWnd = XtVaCreateManagedWidget("main_window", ...
m_wgDrawingArea = XtVaCreateWidget("Test",...
XtVaSetValues(m_wgMainFrm, XmNmwmDecorations, (MWM_DECOR_BORDER), NULL);
XtUnmapWidget(m_wgMainFrm);
XtMapWidget(m_wgMa... |
My compiler warns:operation on j may be undefined
Here's the C code:
```
for(int j = 1; pattern[j] != '\0' && string[i] != '\0';){
if(string[i+j] != pattern[j++]){//this is on the warning
found = 0;
break;
}
}
```
Is that undefined?
|
YES.string[i+j] != pattern[j++]is having two different execution based on variablejwithout anysequence pointin between. So it is example ofundefined behaviour.
|
How can i know the size of the array using a pointer that is allocated using malloc?
```
#include <stdio.h>
int main(){
int *ptr = (int *)malloc(sizeof(int * 10));
printf("Size:%d",sizeof(ptr));
free(ptr_one);
return 0;
}
```
I get only the size of the pointer in this case which is 8.How to modify t... |
You cannot.You will need to do the bookkeeping and keep track of it yourself. Withnewyou allocate dynamic memory and while deallocating the memory you just calldelete, which knows how much memory it has deallocate because the language takes care of it internally so that users do not need to bother about the bookkeepin... |
What does the operator<(less-than) do?Also, can you explain why didfor-loopended?
```
main()
{
int i = 1, j = 1 ;
for ( ; j ; printf ("%d%d\n", i,j))
{
j = i++ < 5 ;
}
return 0;
}
```
I got the output as
```
21
31
41
51
60
```
|
The code checks ifiis smaller than 5, then incrementsi. The result of the comparison is stored inj.
It is quite an obscure way to make a loop like this. Not very readable.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.