Govt Exams
The 'const' keyword creates a read-only variable. Once initialized, attempting to modify a const variable results in a compilation error (error: assignment of read-only variable). This is enforced at compile-time, not runtime.
volatile tells compiler not to optimize variable accesses and to fetch fresh value from memory, useful for hardware registers and shared memory, but doesn't guarantee thread-safety without synchronization.
int max is ~2.1 billion, long int varies (may be 32 or 64 bits). long long int guarantees 64 bits with max ~9.2 quintillion, sufficient for 10 billion.
int arr[3] = {1, 2, 3};
int *p = arr;
printf("%d %d", *p, *(p+2));
p points to arr[0] which is 1. p+2 points to arr[2] which is 3. Therefore output is '1 3'.
register requests compiler to store variable in CPU register for faster access but falls back to memory if unavailable, combining automatic allocation with optimization hints.
float x = 0.1 + 0.2;
if(x == 0.3) printf("Equal"); else printf("Not Equal");
Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation. Direct comparison with == fails.
signed int reserves 1 bit for sign, giving range -2147483648 to 2147483647. unsigned int uses all 32 bits for magnitude, giving 0 to 4294967295.
int a = 5;
int *p = &a;
int **q = &p;
printf("%d", **q);
q is a pointer to pointer p. *q dereferences q to get p, and **q dereferences p to get the value of a, which is 5.
char data type typically occupies 1 byte, which is the minimum. int is 4 bytes, float is 4 bytes, and double is 8 bytes on most systems.
The 'const' keyword declares a constant variable whose value cannot be modified after initialization. Attempting to modify it results in a compile-time error.