ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Pair { int first; int second; };
struct Pair makePair(int a, int b) {
return (struct Pair){a, b};
}
int main(void) {
struct Pair p = makePair(3, 4);
printf("%d %d", p.first, p.second);
}- A. 3 4
- B. 4 3
- C. Compile-time error: compound literals cannot be used in a return statement
- D. 0 0
Correct answer: A. 3 4
(struct Pair){a, b} is a compound literal (a C99 feature), creating an unnamed temporary struct value initialised with a and b, which is then returned by value, copying its contents to the caller. p.first=3, p.second=4.
More C Programming questions
- What is printed? c int main(void) { int a = 10, b = 3; printf("%d %d %f", a / b, a % b, (float)a / b); }
- What is printed? c int main(void) { char ch = 'A'; int code = ch + 1; printf("%d %c", code, (char)code); }
- What is printed? c int main(void) { int n = 17; int isPrime = 1; for (int i = 2; i i <= n; i++) { if (n % i == 0) { isPrime = 0; break; }…
- What is printed? c int main(void) { int a = 5; int b = a; b = b + 10; int p = &a; p = p + 100; printf("%d %d", a, b); }
- Assume a 64-bit LP64 ABI. What is printed? c struct Matrix3x3 { int data[3][3]; }; int trace(struct Matrix3x3 m) { int sum = 0; for (int i…
- Assume 32-bit int. What is printed? c int a = 5; int b = a > 0 ? 1 : a < 0 ? -1 : 0; int c = -5; int d = c > 0 ? 1 : c < 0 ? -1 : 0…