Home »
Code Examples »
C Code Examples
C - Assign one struct to another Code Example
The code for Assign one struct to another
#include <stdio.h>
int main() {
struct student {
char name[30];
int age;
};
struct student std1 = {"Alvin", 21};
struct student std2;
// Assigning std1 to std2
std2 = std1;
// printing
printf("std1: %s, %d\n", std1.name, std1.age);
printf("std2: %s, %d\n", std2.name, std2.age);
return 0;
}
/*
Output:
std1: Alvin, 21
std2: Alvin, 21
*/
Code by IncludeHelp,
on August 11, 2022 16:11