732 views
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);

}

2 Answers

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;)



 

selected by
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

edited by

Related questions

3 votes
3 votes
2 answers
1
sabir asked Nov 24, 2015
867 views
Main () { int a [3] [4] = $\begin{pmatrix} 1&2&3&4 \\ 5&6&7&8 \\ 9&10&11&12 \\ \end{pmatrix}$ printf ("\n% u% u% u", a[0]+1, * (a[0] + 1), *(*(a + 0)+1)); }What is the o...
1 votes
1 votes
1 answer
2
set2018 asked Nov 4, 2017
344 views
0 votes
0 votes
1 answer
3
0 votes
0 votes
1 answer
4
Anirudh Kaushal asked Apr 4, 2022
261 views
#include<stdio.h int main() { char num = '\011'; printf("%d",num); return 0; }