xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to inherit a struct by another struct in C
C Online Editor
Execute Code
More C Sample Codes
#include <stdio.h> #include <string.h> // Define a struct Person struct Person { char Name[50]; int Age; }; // Define a struct Student struct Student { struct Person base; // Include the Person struct as part of the Student struct int StudentId; }; int main() { struct Student studentObj; // Assign values to the fields of the Person base strcpy(studentObj.base.Name, "John"); //strcpy function to copy the string "John" into studentObj.base.Name studentObj.base.Age = 15; studentObj.StudentId = 11; printf("%s is %d years old. His student id is %d.\n", studentObj.base.Name, studentObj.base.Age, studentObj.StudentId); return 0; }