Pointer - Study Mode
[#166] What will be the output of the following C code? #include <stdio.h>
void m(int *p, int *q)
{
int temp = *p
*p = *q
*q = temp
}
void main()
{
int a = 6, b = 5
m(&a, &b)
printf("%d %d
", a, b)
}
Correct Answer
(A) 5 6
[#167] What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 97, *p = &i
foo(&p)
printf("%d ", *p)
return 0
}
void foo(int **p)
{
int j = 2
*p = &j
printf("%d ", **p)
}
Correct Answer
(A) 2 2
[#168] What will be the output of the following C code? #include <stdio.h>
int main()
{
void *p
int a[4] = {1, 2, 3, 8}
p = &a[3]
int *ptr = &a[2]
int n = p - ptr
printf("%d
", n)
}
Correct Answer
(B) Compile time error
[#169] What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s= "hello"
char *p = s
printf("%c %c", 1[p], s[1])
}
Correct Answer
(D) e e
[#170] What will be the output of the following C code? #include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, 4, 5}
int i = 0, j = 0
for (i = 0
i < 2
i++)
for (j = 0
j < 3
j++)
printf("%d", a[i][j])
}
Correct Answer
(A) 1 2 3 4 5 0