Home » C Programming » Structures » Question
  1. 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);
    }
    1. Compilation Error
    2. Garbage value
    3. Segmentation fault
    4. Undefined behaviour
    5. 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);
^~



Your comments will be displayed only after manual approval.