Govt. Exams
Entrance Exams
Both 'int x;' and 'static int x;' allocate memory. Extern only declares without allocation.
int x = 10;
int *p = &x;
printf("%d", *p + 5);
*p dereferences pointer to get value 10, then 10+5=15 is printed.
Static variables retain their values between function calls and are initialized only once, maintaining state across invocations.
%ld is for long int, %lld is for long long int, and %d is for regular int. Using wrong specifier can cause undefined behavior.
Uninitialized local variables contain garbage values (random data from memory). Static/global variables are initialized to 0 by default.
When assigning a double to int, C performs implicit type conversion with truncation (not rounding). The decimal part is discarded.
char (signed) has range -128 to 127, while unsigned char has 0 to 255. The latter can represent extended ASCII characters (128-255).
# Understanding `sizeof()` Operator in C
The `sizeof()` operator returns the size of data types in bytes, which varies depending on the compiler and system architecture.
Step 1: Analyze sizeof(int)
In C, the size of `int` is implementation-defined and depends on the system architecture and compiler.
Step 2: Analyze sizeof(char) and Calculate Total
The `char` data type always occupies exactly 1 byte across all standard C implementations, but `int` varies by platform.
For a 16-bit system: \(2 + 1 = 3\) bytes
For a 32-bit system: \(4 + 1 = 5\) bytes
For a 64-bit system: \(4 + 1 = 5\) bytes (typically)
The output depends on the system's architecture. The minimum guaranteed value is 3 bytes (on 16-bit systems), but it can be higher on modern systems.
Correct Answer: (C) Depends on system (at least 3)
C allows implicit type conversion. When assigning larger to smaller type, truncation or data loss may occur without any compiler error.
Both 'const int' and 'int const' are valid and equivalent ways to declare a constant integer in C.