2 2 votes #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); } Programming in C pointers easy + – Manali Sikdar 1.3k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply shivanisrivarshini commented Apr 14, 2016 reply Follow flag Error at printf statement 0 0 replyShare Arjun commented Apr 14, 2016 reply Follow flag thats a typo- corrected now.. 0 0 replyShare Please log in or register to add a comment.
Best answer 1 1 vote 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;) gatecse answered Sep 7, 2014 • selected Apr 14, 2016 by Arjun gatecse comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes 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 srestha answered Apr 13, 2016 • edited Apr 13, 2016 by srestha srestha comment Share Follow See 1 comment 1 1 comment reply Arjun commented Apr 14, 2016 reply Follow flag no. For every pointer in C, it must get a valid memory address before being dereferenced (using *). 0 0 replyShare Please log in or register to add a comment.