Pointers
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "Interview, Mania\n";
char *strc = "Welcome to\n";
strcpy(strc, str);
printf("%s\n", strc);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Crash/segmentation fault
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int arr[5] = {61, 62, 63, 64, 65};
void *p = &arr[1];
void *p1 = &arr[5];
int Res = 0;
Res = p1 - p;
printf("%d\n", Res);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
16
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int array[3] = {16, 17, 18};
int *p = &array[1];
float m = 1;
p = p + m;
printf("%d\n", *p);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:7:15: error: invalid operands to binary + (have ‘int *’ and ‘float’)
p = p + m;
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int num[5] = {15, 25, 35, 45, 55};
int *ptr1 = &num[3];
int *ptr2 = &num[4];
ptr2 = ptr2 * 1;
printf("%d\n", *ptr2);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Compilation Error
main.c: In function ‘main’:
main.c:7:21: error: invalid operands to binary * (have ‘int *’ and ‘int’)
ptr2 = ptr2 * 1;
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int array1[5] = {10, 20, 30, 40, 50};
int array2[5] = {11, 21, 31, 41, 51};
int R = &array2[3] - &array1[2];
printf("%d\n", R);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
-7