Entrance Exams
Govt. Exams
An empty structure in C has a size of 1 byte. This is to ensure each structure instance has a unique address in memory.
int a = 5;
int b = ++a + a++;
printf("%d", b);
++a increments a to 6 and returns 6. Then a++ returns 6 and increments a to 7. So b = 6 + 6 = 12.
Declaration tells the compiler about a variable's name and type (e.g., 'extern int x;'). Definition actually allocates memory (e.g., 'int x = 5;'). A variable can be declared multiple times but defined only once.
Array name decays to pointer. p[5] is equivalent to *(p+5) which is *(arr+5) or arr[5]. This demonstrates pointer arithmetic.
When static is used with a global variable, it restricts its scope to the file where it is declared. Without static, global variables are accessible across files using extern.
In structures, each member has its own memory location. In unions, all members share the same memory location, so only one can hold a value at a time.
Since both 5 and 2 are integers, integer division occurs (5/2 = 2). The result 2 is then converted to float as 2.000000.
/* */ is used for multi-line comments in C. // is used for single-line comments and was introduced in C99.
calloc(n, size) allocates n blocks of size bytes and initializes to 0. malloc(size) allocates size bytes without initialization. calloc() is typically slower due to initialization.
The free() function deallocates memory that was previously allocated using malloc(), calloc(), or realloc(). delete() is used in C++.