Parentheses () have the highest precedence among all operators in C. They are always evaluated first in any expression.
The strlen() function returns the length of a string as an int value, representing the number of characters.
Variable names in C must start with a letter or underscore, not a digit. _variable is valid. '2var' starts with digit, 'var-name' contains hyphen (invalid), 'var name' contains space (invalid).
The stdio.h header file contains declarations for standard input/output functions like printf() and scanf().
In a struct, each member has its own memory allocation, so the total size is the sum of all members. In a union, all members share the same memory location, so the size equals the largest member. Only one member can hold a value at a time in a union.
#define MAX 5
int main() {
int arr[MAX];
printf("%d", sizeof(arr)/sizeof(arr[0]));
return 0;
}
int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
int *ptr = (int *)arr;
printf("%d", *(ptr + 5));
A 2D array is stored in row-major order in memory: 1,2,3,4,5,6,7,8,9. When ptr is cast to int*, ptr+5 points to the 6th element (0-indexed), which is 6.
Both declarations are equivalent. 'const int * const ptr' and 'int const * const ptr' declare a constant pointer to a constant integer. The first const makes the integer constant, the second const makes the pointer constant.
#include
int main() {
int a = 5;
printf("%d %d %d", a++, ++a, a);
return 0;
}
This code contains undefined behavior because variable 'a' is modified multiple times (a++, ++a) without intervening sequence points in the same expression. The order of evaluation is unspecified, making the result compiler-dependent.
int x = 10;
int y = 20;
int z = x < y ? x++ : y++;
printf("%d %d %d", x, y, z);