Guest User

Untitled

a guest
Oct 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. //Declaration
  5. struct student{
  6. // string muss be terminated by ['\0']
  7. char name[20];
  8. int roll;
  9. int age;
  10. };
  11.  
  12. //create struct variable
  13. struct student s1 = {"Bob", 3, 15};
  14.  
  15. //or you can also do
  16. struct student s2;
  17.  
  18. printf("Enter your name\n");
  19. scanf("%s",s2.name);
  20. printf("Enter your roll\n");
  21. scanf("%d",&s2.roll);
  22. printf("Enter your age\n");
  23. scanf("%d",&s2.age);
  24.  
  25. //Accessing struct variable
  26. printf("Name: %s\n",s1.name);
  27.  
  28. return 0;
  29. } // example taken from youtube channel We the computer guys
Add Comment
Please, Sign In to add comment