© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024
S. DmitrovićModern C for Absolute Beginnershttps://doi.org/10.1007/979-8-8688-0224-9_22

22. Exercises

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 

22.1 Structure Definition

Write a program that defines a simple structure called Person. The structure has the char*, int, and double fields. Declare a variable of this structure type inside the main and assign values to each member field. Print out the values:
#include <stdio.h>
struct Person
{
      char *name;
      int age;
      double salary;
};
int main(void)
{
      struct Person o;
      o.name = "John Doe";
      o.age = 35;
      o.salary = 2500.00;
      printf("Name: %s\n", o.name);
      printf("Age: %d\n", o.age);

Get Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.