Govt. Exams
Entrance Exams
Using scanf("%10s", str) limits input to 10 characters, preventing buffer overflow. The gets() function is deprecated and unsafe.
'const int *ptr' makes the data constant, 'int * const ptr' makes the pointer constant, and 'const int * const ptr' makes both constant.
The 'volatile' keyword tells the compiler not to optimize accesses to a variable, as its value can change from external sources (hardware, signals, etc.).
Strings in C are represented using double quotes and stored in character arrays. Single quotes are for single characters.
In C, when both operands are integers, division performs integer division, discarding the fractional part. 5/2 = 2.
A signed char is 1 byte (8 bits) and can represent values from -128 to 127 using two's complement representation.
When 'static' is used with a global variable, it restricts its scope to the current file (internal linkage), making it not accessible from other files.
Global variables are stored in the data segment (also called BSS segment for uninitialized globals). Local variables use the stack.
The 'long' modifier cannot be used with 'float'. You can only use 'double' or 'long double' for longer floating-point types.
#include
int main() {
int a = 5, b = 10;
a = b++;
printf("%d %d", a, b);
return 0;
}
b++ returns the current value of b (10) before incrementing, so a = 10. Then b increments to 11.