Pointers
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
void *ptr1;
int var[5] = {50, 60, 70, 80, 90};
ptr1 = &var[3];
int *ptr2 = &var[4];
int m = (int*)ptr1 - ptr2;
printf("%d\n", m);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
-1
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
void *ptr1;
int num[5] = {10, 20, 30, 40, 80};
ptr1 = &num[4];
int *ptr2 = &num[3];
int R = ptr1 - ptr2;
printf("%d\n", R);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:8:22: error: invalid operands to binary - (have ‘void *’ and ‘int *’)
int R = ptr1 - ptr2;
- What will be the output of the following C code?
#include <,stdio.h>
void main()
{
char *n= "KRISHANA";
char *m = n + 3;
printf("%c %c", *m, n[5]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
S A
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "SUJIT";
char *ptr = str * 5;
printf("%c\t%c", *ptr, str[3]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:5:25: error: invalid operands to binary * (have ‘char *’ and ‘int’)
char *ptr = str * 5;
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "InterviewMania";
char *ntr = "Mania";
char *ptr = str + ntr;
printf("%c\t%c", *ptr, str[1]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:6:25: error: invalid operands to binary + (have ‘char *’ and ‘char *’)
char *ptr = str + ntr;