Govt. Exams
Entrance Exams
x++ is post-increment (returns 5, then x becomes 6), ++x is pre-increment (x becomes 7, then returns 7). The order of evaluation in printf is implementation-dependent, but typically right to left, giving 5 7.
In C, identifiers can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores (_), and must start with a letter or underscore. The dollar sign (\() is not allowed, making 'my\)var' invalid.
Both char s[] (array notation) and char *s (pointer notation) are valid ways to pass strings to functions in C. C does not have a built-in string type; strings are represented as character arrays or pointers to char.
C does not perform bounds checking on arrays. Accessing beyond array bounds results in undefined behavior - it may access garbage values, crash, or seem to work without error. This is a common source of bugs.
Static variables are initialized only once and retain their value throughout the program execution. Their value persists between function calls.
ptr is reassigned to point to b. When we dereference ptr using *ptr, we get the value stored at b, which is 10.
Linear search checks each element sequentially. In the worst case, it needs to check all n elements, resulting in O(n) time complexity.
ptr[2] is equivalent to *(ptr+2), which dereferences the pointer and returns the value at the third element (index 2).
The pre-increment operator (++x) increments x from 5 to 6 before using its value in printf(). So the output is 6.
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.