ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int main(void) {
int x = 0;
int y = (x = 5, x + 1);
printf("%d %d", x, y);
}- A. 0 6
- B. 5 6
- C. 0 1
- D. 5 5
Correct answer: B. 5 6
The comma operator evaluates its left operand (x=5, setting x to 5, discarding that assignment's value) then evaluates and yields its right operand (x+1 = 6) as the whole expression's value; y = 6, x = 5.
More C Programming questions
- What is printed? c int main(void) { int arr[3] = {1, 2, 3}; int p = arr; for (int i = 0; i < 3; i++, p++) { printf("%d ", p); } }
- Assume 32-bit int. What is printed? c int x = 7; int y = x > 5 && x < 10 ? x 2 : x + 1; printf("%d", y);
- What happens when this runs? c int p = malloc(10 sizeof(int)); for (int i = 0; i <= 10; i++) { p[i] = i; } free(p);
- Assume 32-bit int. What is printed? c int a = 6; int b = a++ 2; printf("%d %d", a, b);
- What is printed? c #define MAXSIZE 100 #if MAXSIZE > 50 const char label = "large"; #else const char label = "small"; #endif printf("%s"…
- Assume 32-bit int. What is printed? c int x = 10; int p = &x; p += 5; p = 2; printf("%d", x);