ProgrammingHardProduct-company MCQ pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Employee {
char name[20];
int id;
float salary;
};
struct Employee e1 = {"Alice", 101, 50000.0f};
struct Employee e2 = e1;
e2.id = 102;
printf("%d %d", e1.id, e2.id);- A. 102 102
- B. 101 102
- C. 101 101
- D. Compile-time error: structs cannot be copy-assigned directly
Correct answer: B. 101 102
struct Employee e2 = e1; performs a full MEMBER-WISE copy of the entire struct (C supports whole-struct assignment/initialization natively), creating an entirely independent object. Changing e2.id afterward has no effect on e1's own copy of id, which stays 101.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point make(int a, int b) { struct Point p = {a, b}; return…
- Assume a 64-bit LP64 ABI. What is printed? c typedef struct { int x; int y; } Point; Point p1 = {1, 2}; Point p2 = {1, 2}; printf("%d"…
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int value; struct Node next; }; struct Node a = {1, NULL}; struct Node b = {2…
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point origin = {0, 0}; struct Point p1 = &origin; struct…
- Assume a 64-bit LP64 ABI. What is printed? c struct Config { int verbose : 1; int debug : 1; int level : 4; }; struct Config cfg = {0}…
- What is printed? c int sumDigits(int n) { if (n == 0) return 0; return (n % 10) + sumDigits(n / 10); } int main(void) { printf("%d"…