2 votes 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 asked Sep 7, 2014 Manali Sikdar 732 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply shivanisrivarshini commented Apr 14, 2016 reply Follow Share Error at printf statement 0 votes 0 votes Arjun commented Apr 14, 2016 reply Follow Share thats a typo- corrected now.. 0 votes 0 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes 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 See all 0 reply Please log in or register to add a comment.
0 votes 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 See all 1 1 comment reply Arjun commented Apr 14, 2016 reply Follow Share no. For every pointer in C, it must get a valid memory address before being dereferenced (using *). 0 votes 0 votes Please log in or register to add a comment.