Pointers
- Comment on the following pointer declaration.
int *p, n;
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
p is a pointer to integer, n is not
- What will be the output of the following C code?
#include <stdio.h>
int *fun();
int main()
{
int *ptr = fun();
printf("%d\n", *ptr);
}
int *fun()
{
int n = 12;
return &n;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Segmentation fault
- What will be the output of the following C code?
#include <stdio.h>
int *fun();
int main()
{
int *ptr = fun();
printf("%d\n", *ptr);
}
int *fun()
{
int *p = (int*)malloc(sizeof(int));
*p = 11;
return p;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
11
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int num = 110;
void *ptr = #
printf("%f\n", *(float*)ptr);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
0.000000
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int n = 12;
void *ptr = &n;
printf("%d\n", (int)*ptr);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:6:29: warning: dereferencing ‘void *’ pointer
printf("%d\n", (int)*ptr);
^~~~
main.c:6:24: error: invalid use of void expression
printf("%d\n", (int)*ptr);