Knowee
Questions
Features
Study Tools

#include <stdio.h> struct student { int no; char name[20]; } int main() { struct student s; s.no = 8; printf("hello"); } hello 8 Hello No Output Compile time error

Question

#include <stdio.h>

struct student

{

int no;

char name[20];

}

int main()

{

struct student s;

s.no = 8;

printf("hello");

}

hello 8

Hello

No Output

Compile time error

🧐 Not the exact question you are looking for?Go ask a question

Solution

The code you provided will result in a compile time error.

The reason is that you have declared a structure 'student' but you didn't close the declaration with a semicolon.

Also, you are trying to print "hello" but you didn't include a newline character (\n) or any other output after "hello", so even if the code did compile, it wouldn't output anything after "hello".

Here is the corrected version of your code:

#include <stdio.h>

struct student
{
    int no;
    char name[20];
}; // Added semicolon here

int main()
{
    struct student s;
    s.no = 8;
    printf("hello\n"); // Added newline character here
    printf("%d", s.no); // This will print the number 8
    return 0;
}

This code will output:

hello
8

This problem has been solved

Similar Questions

0/0

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.