Pointers
- What will be the output of the following C code?
#include <stdio.h>
void fun(int*);
int main()
{
int num = 10;
fun((&num)++);
}
void fun(int *ptr)
{
printf("%d\n", *ptr);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:6:19: error: lvalue required as increment operand
fun((&num)++);
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int var = 101;
int *p = &var;
printf("%d\n", *p);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
101
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int var = 10;
int *p = &15;
printf("%p\n", p);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:5:18: error: lvalue required as unary ‘&’ operand
int *p = &15;
- 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++;