ProgrammingHardTCS NQT · Infosys
char s[] = "abc"; s[0] = 'x'; printf("%s", s); prints what?
- A. xbc
- B. abc
- C. xbcd
- D. bc
Correct answer: A. xbc
A char array initialised from a string literal is a modifiable copy, so writing s[0] changes it. The literal itself, when given as char *, would be the non-modifiable case.
More C Programming questions
- unsigned int n = 1u; unsigned int r = n << 31; What is r?
- int a = -7, b = 2; What is a / b b + a % b?
- int m[2][2] = {{1, 2}, {3, 4}}; int (r)[2] = m; What is r[1][0] + (r[0] + 1)?
- uint32t n = 100000u; uint32t t = n (n + 1) / 2; What is t?
- int x = 0; for (int i = 0; i < 5; i++) x = x ^ i << 1; What is x at the end?
- uint16t a = 300, b = 300; uint16t p = a b; What is p?