Recent questions tagged pointers

5 5 votes
2 2 answers
300
300 views
What is the output of the following code?#include <stdio.h struct Item { int code; int price; }; void f(struct Item x) { x.code = x.code + 1; x.price = x.price + 50; } vo...
7 7 votes
2 2 answers
311
311 views
What is the output of the following code?#include <stdio.h struct Item { int code; int price; }; void update(struct Item *p) { p->price = p->price + 20; (*p).code = (*p)....
6 6 votes
2 2 answers
280
280 views
What is the output of the following code?#include <stdio.h struct Box { int width; int height; }; int main() { struct Box b = {4, 6}; struct Box *p = &b; p->width = p->wi...
5 5 votes
2 2 answers
288
288 views
What is the main issue in the following code? Assume both $\texttt{malloc()}$ calls succeed.#include <stdio.h #include <stdlib.h int main() { int *p = (int *)malloc(sizeo...
4 4 votes
2 2 answers
288
288 views
What will happen in the following code?#include <stdio.h #include <stdlib.h int main() { int *p = (int *)malloc(sizeof(int)); *p = 10; free(p); printf("%d", *p); return 0...
5 5 votes
2 2 answers
289
289 views
What is the output of the following code? Assume $\texttt{malloc()}$ succeeds.#include <stdio.h #include <stdlib.h int main() { int *p = (int *)malloc(3 * sizeof(int)); p...
6 6 votes
2 2 answers
251
251 views
What is the output of the following code?#include <stdio.h int main() { int x = 25; void *p = &x; printf("%d", *(int *)p); return 0; }$\texttt{25}$ Address of $\texttt{x}...
7 7 votes
2 2 answers
292
292 views
Which of the following correctly describes the declarations?int *a[10]; int (*p)[5];$\texttt{a}$ is a pointer to an array of $10$ integers, and $\texttt{p}$ is an array o...
6 6 votes
2 2 answers
317
317 views
What is the output of the following code?#include <stdio.h int main() { int a[3] = { {1, 2}, {3, 4}, {5, 6} }; int (*p) = a; p++; printf("%d %d %d", (*p)[0], *(*(p + 1)...
8 8 votes
3 3 answers
413
413 views
What is the output of the following code?#include <stdio.h int main() { int a [3] = { {2, 4, 6}, {8, 10, 12} }; printf("%d %d %d", a , *(*(a + 1) + 1), *(*a + 2)); retur...
7 7 votes
3 3 answers
324
324 views
What is the output of the following code?#include <stdio.h void update(int q, int *r) { q = q + 5; *q = r; q = q + 2; } int main() { int x = 3, y = 8; int *p = &x; u...
8 8 votes
3 3 answers
339
339 views
What is the output of the following code?#include <stdio.h int main() { int a = 5, b = 9; int *p = &a; int q = &p; *p = *p + 2; *q = &b; q = q + 3; printf("%d %d %d", ...
8 8 votes
3 3 answers
360
360 views
What is the output of the following code?#include <stdio.h int main() { int x = 10; int *p = &x; int q = &p; q = q + 4; *p = *p + 1; printf("%d %d", x, q); return 0; ...
6 6 votes
1 1 answer
237
237 views
What is the output of the following code?#include <stdio.h int main() { char str[] = "CODE"; char *p = str; p++; *p = 'A'; printf("%s %c", str, *(p + 2)); return 0; }$\te...
6 6 votes
1 1 answer
209
209 views
What is the output of the following code?#include <stdio.h int main() { char str[] = "GATE"; char *p = str; printf("%c %c %s", str , *(p + 2), p + 1); return 0; }$\texttt...
6 6 votes
1 1 answer
197
197 views
What will happen when the following code is compiled?#include <stdio.h int main() { int a[] = {10, 20, 30}; a = a + 1; printf("%d", *a); return 0; }$\texttt{10}$ $\texttt...
5 5 votes
1 1 answer
192
192 views
Consider the following declarations:#include <stdio.h int main() { int a[4] = {6, 4, 1, 2}; int b[8] = {9, 8, 11, 10, 5, 7, 0, 3}; int *p = &a ; int *q = b; printf("%p", ...
7 7 votes
2 2 answers
256
256 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {5, 10, 15, 20}; int *p = a + 1; printf("%d %d %td", *(p + 1), p , (p + 2) - a); return ...
8 8 votes
2 2 answers
284
284 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; int *p = a + 2; printf("%d %d %td", p[-1], 1[p], p - a); return 0; }$\...
7 7 votes
3 3 answers
251
251 views
What is the output of the following code?#include <stdio.h int main() { int a[4] = {6, 4, 1, 2}; int b[8] = {9, 8, 11, 10, 5, 7, 0, 3}; int *p = &a ; int *q = b; int *r =...
8 8 votes
2 2 answers
244
244 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {3, 6, 9, 12, 15}; int *p = a + 1; printf("%d %d %td", *p, *(p + 2), p - a); return 0; }...
8 8 votes
2 2 answers
259
259 views
What is the output of the following code?#include <stdio.h int main() { int a[10] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; int *b = a + 4; int *c = &(a[4]); printf("%d...
7 7 votes
2 2 answers
298
298 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; printf("%d %d %d", *a, *(a + 3), 3[a]); return 0; }$\texttt{2 6 8}$ $\...
9 9 votes
2 2 answers
310
310 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {10, 20, 30, 40}; int *p = a; int *q = &a[3]; if (p < q) p = p + 2; else q = q - 1; prin...
9 9 votes
2 2 answers
281
281 views
What is the output of the following code?#include <stdio.h int main() { int a [3] = { {1, 2, 3}, {4, 5, 6} }; int (*p)[3] = a; printf("%d %d %d", p, *(*(p + 1) + 2), *(*...
8 8 votes
1 1 answer
216
216 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {5, 10, 15}; int *p = a; printf("%d ", (*p)++); printf("%d ", *p++); printf("%d ", ++*p)...
10 10 votes
1 1 answer
212
212 views
What is the output of the following code?#include <stdio.h void change(int pp, int *q) { pp = pp + 3; *pp = q; pp = pp + 4; } int main() { int a = 5, b = 10; int *p ...
8 8 votes
1 1 answer
211
211 views
What is the output of the following code?#include <stdio.h int main() { int a = 10; int *p = &a; int q = &p; q = q + 5; *p = *p + 2; printf("%d %d", a, q); return 0; ...
8 8 votes
1 1 answer
253
253 views
What is the output of the following code?#include <stdio.h void fun(int a[], int *p) { a = a + 5; *(p + 2) = *(p + 2) + 10; p++; *p = *p + 1; } int main() { int arr[] =...
8 8 votes
1 1 answer
212
212 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {10, 20, 30}; int *p = a; printf("%d ", *p++); printf("%d ", *p); printf("%d", ++*p); re...