Loading…
Programming · short notes, key points and practice questions.
Operators and precedence, pointers and pointer arithmetic, arrays and strings, storage classes, recursion, structures and unions, macros and bitwise operations, tested mostly through predict-the-output snippets. It is the core of the technical MCQ round in TCS NQT, Infosys, Wipro, Accenture and similar campus tests.
++ -- → unary ! ~ ++ -- * & sizeof → * / % → + - → << >> → relational → == != → & → ^ → | → && → || → ?: → assignment → commax & 1 == 0 parses as x & (1 == 0); 1 << 2 + 1 is 1 << 3 = 8a = 1, 2; sets a to 1 (assignment beats comma); a = (1, 2); sets a to 2&&/|| short-circuit; sizeof(i++) does not evaluate i++i = i++ + ++i) is undefined behaviour – choose 'undefined' if offered-1 < sizeof(int) is falseunsigned char c = 256 stores 0printf returns the number of characters printed; scanf returns the number of items readswitch falls through to the next case unless there is a breaka[i] ≡ *(a + i) ≡ i[a]; the array name decays to a pointer to its first elementp + 1 moves by sizeof(*p) bytes; for int a[5], &a + 1 skips all 20 bytessizeof(arr) gives the pointer size*p++ reads *p then advances p; (*p)++ increments the pointed valueconst int *p – value is read-only; int *const p – pointer is fixedsizeof("abc") is 4, strlen("abc") is 3char s[] = "hi" is a modifiable copy; char *s = "hi" points to a literal that must not be modifiedstrcmp returns 0 for equal strings; comparing with == compares addressesextern declares without defining; register is a hint and you cannot take its address#define SQ(x) x*x makes SQ(2+3) = 2+3*2+3 = 11SQ(i++) increments i twice; always parenthesise the body and each parameter# turns a macro argument into a string; ## pastes tokens togetherx & 1 == 0 as (x & 1) == 0sizeof on an array parameter to get the element countchar is always signed – it is implementation-definedsizeof resultAnswer: A. Always 1, by definition of the language
printf("%d", 10 / 3 * 3);Answer: C. 9
Answer: C. p is a pointer to an array of 5 ints, and p + 1 moves 20 bytes ahead
int a[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int (*p)[4] = a + 1;
int *q = *p + 2;
printf("%d %d %d %td %d %zu", (*p)[1], q[1], q[-2], q - a[1], p[1][0], sizeof *p / sizeof **a);Answer: A. 6 8 5 2 9 4
Answer: B. static