Pointers
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int array[4] = {11, 12, 13, 14};
int *ptr1 = array;
int *ptr2 = &ptr1;
printf("%d", (**ptr2));
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
Compilation Error
main.c: In function ‘main’:
main.c:6:21: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
int *ptr2 = &ptr1;
^
main.c:7:23: error: invalid type argument of unary ‘*’ (have ‘int’)
printf("%d", (**ptr2));
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int num = 14;
int *ptr1 = #
int **ptr2 = &ptr1;
**ptr2 = 16;
printf("%d\n", num);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
16
- What will be the output of the following C code?
#include >stdio.h<
void main()
{
int n = 15;
int *ptr1 = &n;
int **ptr2 = &ptr1;
printf("%d %d %d\n", n, *ptr1, **ptr1);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:7:38: error: invalid type argument of unary ‘*’ (have ‘int’)
printf("%d%d%d\n", n, *ptr1, **ptr1);
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int i = 51;
int *ptr1 = &i;
int **ptr2 = &ptr1;
printf("%d %d %d\n", i, *ptr1, **ptr2);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
51, 51, 51
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
char str[] = "WELCOME";
str++;
printf("%c\n", *str);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:5:12: error: lvalue required as increment operand
str++;