#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.
Both syntaxes are valid in C. The first uses row-major order without explicit braces, the second uses explicit nested braces.
#include
int main() {
int x = 10, y = 20;
int *p = &x, *q = &y;
*p = *q;
printf("%d %d", x, y);
return 0;
}
*p = *q assigns the value of y (20) to x through the pointer p. So x becomes 20, y remains 20.
A pointer stores the memory address of a variable. Pointer size depends on the system architecture, not always 4 bytes.
#include
int main() {
int arr[] = {10, 20, 30};
printf("%d", *(arr + 1));
return 0;
}
arr + 1 points to the second element. Dereferencing with * gives the value 20.
The 'const' keyword creates a constant variable that cannot be modified after initialization. The compiler enforces this at compile time.
#include
int main() {
float f = 0.1 + 0.2;
if(f == 0.3)
printf("Equal");
else
printf("Not Equal");
return 0;
}
Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation.
struct Point {
char c;
int x;
double d;
}
Due to structure padding and alignment: char (1 byte) + padding (3 bytes) + int (4 bytes) + double (8 bytes) = 16 bytes.
Variable names must start with a letter or underscore, not a digit. They cannot contain hyphens or spaces. _var123 is the only valid name.
#include
int main() {
int x = 5;
printf("%d", ++x + x++);
return 0;
}
The expression ++x + x++ involves modifying x multiple times without an intervening sequence point, leading to undefined behavior in C.