Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Real-Life Example

Real-Life Example

In our examples, we frequently simplify variable names to reflect their data type (e.g., myInt or myNum for integers, myChar for characters, etc.).

This simplification is employed to prevent confusion.

For a practical demonstration of variable usage, consider the following program.

It stores various data related to a college student:

Example

// Student data
int studentID = 15;
int studentAge = 23;
float studentFee = 75.25;
char studentGrade = ‘B’;

// Print variables
printf(“Student id: %d\n”, studentID);
printf(“Student age: %d\n”, studentAge);
printf(“Student fee: %f\n”, studentFee);
printf(“Student grade: %c”, studentGrade); 

Calculate the Area of a Rectangle

In this practical example, we develop a program to compute the area of a rectangle by multiplying its length and width:

Example

// Create integer variables
int length = 4;
int width = 6;
int area;

// Calculate the area of a rectangle
area = length * width;

// Print the variables
printf(“Length is: %d\n”, length);
printf(“Width is: %d\n”, width);
printf(“Area of the rectangle is: %d”, area);