#include<stdio.h> #include<stdlib.h> int main() { struct xx { int x; char s; }; struct xx *t; t->x=5; t->s='a'; printf("%d %c\n", t->x, t->s); }
struct xx *t; //Here t is a pointer to struct xx t->x=5; Assigns 5 to the int part of struct xx object pointed to by t. But t is not assigned any struct xx object to point to. So, this is doing invalid memory access and should result in segmentation fault. (similar to int *p; *p = 5;)
there is no error in program other than printf statement
printf("%d %c\n",t⟶x, t⟶s); will be the correct statement
only expession syntax will be there
64.3k questions
77.9k answers
244k comments
80.0k users