ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
char *names[] = {"Alice", "Bob", "Carol"};
char **p = names;
p++;
printf("%s %s", *p, *(names + 2));- A. Carol Bob
- B. Alice Bob
- C. Bob Carol
- D. Alice Carol
Correct answer: C. Bob Carol
names is an array of char* (an array of pointers). p starts pointing at names[0]; p++ advances it by one char* (8 bytes), so *p now reads names[1] = "Bob". *(names + 2) indexes directly to names[2] = "Carol".
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int a[5] = {10, 20, 30, 40, 50}; int p = a + 4; int q = a; printf("%ld %d %d", p - q, (p…
- Assume a 64-bit LP64 ABI. What is printed? c void modify(int arr[], int n) { for (int i = 0; i < n; i++) arr[i] += 100; } int main(void) {…
- Assume a 64-bit LP64 ABI. What is printed? c int nums[] = {1, 2, 3, 4, 5}; int p = nums; for (int i = 0; i < 5; i++) { printf("%d ", p); p…
- Assume a 64-bit LP64 ABI. What is printed? c int a = 5; int p = &a; void vp = p; int p2 = (int )vp; p2 = 99; printf("%d %d", a, p);
- Assume a 64-bit LP64 ABI. What is printed? c int a[3] = {1, 2, 3}; int p = a; int q = &a[2]; ptrdifft diff = q - p; printf("%td %d", diff…
- Assume a 64-bit LP64 ABI. What is printed? c int rows = 2, cols = 3; int matrix = malloc(rows sizeof(int )); for (int i = 0; i < rows…