Pointers
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int n = 0;
int *p = &n;
printf("%p\n", p);
p++;
printf("%p\n ", p);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
0x7ffc391e1404
0x7ffc391e1408
- What will be the output of the following C code?
#include <stdio.h>
int n = 0;
void main()
{
int *const p = &n;
printf("%p\n", p);
p++;
printf("%p\n ", p);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
main.c: In function ‘main’:
main.c:7:10: error: increment of read-only variable ‘p’
p++;
- What will be the output of the following C code?
#include <stdio.h>
int num = 0;
void main()
{
int *p = #
printf("%p\n", p);
num++;
printf("%p\n ", p);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Same memory address
- 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);
- 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