ProgrammingHardGATE CS · Campus placements
int *q = NULL; if (q != NULL && *q == 3) printf("yes"); else printf("no"); What is printed?
- A. yes
- B. no
- C. crash
- D. undefined
Correct answer: B. no
The && operator short-circuits, so *q is never evaluated when q is NULL. The else branch runs and prints no.
More C Programming questions
- #define ADD(a,b) a+b. What does printf("%d", 2 ADD(1,2) 3) print?
- #define HALF(x) x / 2. With int a = 5, b = 3, what does printf("%d", HALF(a + b)) print?
- char s[] = "2024"; int sum = 0; for (int i = 0; s[i] != '0'; i++) sum += s[i] - '0'; What is sum?
- int count = 0; for (int i = 1; i <= 10; i++) for (int j = i; j <= 10; j += i) count++; What is count at the end?
- A contest program must test whether n is prime for n up to 10^9 with a 1 second limit. Which method is fast enough for one query?
- How many elements in the 1 to 50 range have exactly three 1 bits in binary?