Structures in C Language

 // Online C compiler to run C program online

#include <stdio.h>

#include<string.h>


struct Student{

    int rollNo;

    char name[50];

    float marks;

// } s1,s2; // we can also declare global objects while defining

}typedef st;


// void display(st *s){

void display(struct Student *s){

    printf("%d\n",s->rollNo);

    printf("%s\n",s->name);

    printf("%f\n",s->marks);

}


int main() {

    // Write C code here

    // printf("Start small. Ship something.");

    // st s1; // This is also correct

    struct Student s1={27,"Gunjan Nayak",99.99}; // this won't raise problem with declaring array characters.

    // s1.rollNo=27;

    // s1.name="Gunjan Nayak"; // This method won't work

    // strcpy(s1.name,"Gunjan Nayak");

    // s1.marks=99.99;

    printf("%d\n",s1.rollNo);

    printf("%s\n",s1.name);

    printf("%f\n",s1.marks);

    display(&s1);

    


    return 0;

}

Comments

Popular posts from this blog

Requests and Urllib

Strings in C Language

Dictionary in Python