-
What will be the output of the following C code?
#include <stdio.h>
struct price
{
int s1;
char s2;
};
typedef struct price* ptr*;
int main()
{
struct price pr[] = {15, 52, 35, 95, 55, 56};
ptr ptr1 = pr;
printf("%d\n", ptr1->s1);
}
-
- Compilation Error
- Garbage value
- Segmentation fault
- Undefined behaviour
- None of these
Correct Option: A
Compilation Error
main.c:7:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
typedef struct price* ptr*;
^
main.c: In function ‘main’:
main.c:11:9: error: unknown type name ‘ptr’; did you mean ‘putc’?
ptr ptr1 = pr;
^~~
putc
main.c:11:20: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
ptr ptr1 = pr;
^~
main.c:12:28: error: invalid type argument of ‘->’ (have ‘int’)
printf("%d\n", ptr1->s1);
^~