1,302 views
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);

}

2 Answers

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



 

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

• edited by
Position:
Show:

Related questions

3 3 votes
2 2 answers
2.1k
2.1k views
sabir asked Nov 24, 2015
2,119 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 1 vote
1 answers 1 answer
758
758 views
set2018 asked Nov 4, 2017
758 views
0 0 votes
1 1 answer
752
752 views
saket jaiswal asked Jan 22, 2025
752 views
code :1 #include <stdio.h int main() { char letters[] = {'A', 'B', 'C'}; for (int i = 0; i < 3; printf("%c", letters[i], i++)) { // Empty body } r...
1 1 vote
1 answers 1 answer
1.4k
1.4k views
abhinowKatore asked Jan 18, 2023
1,447 views
What will be the output of the following program ?answer is 8 but I am getting 5, please explain where I am wrong