Presentation 4
Presentation 4
Data Structures
Introduction
Program/Software
return 0;
}
C program execution steps...
Variables and Datatypes
Variables
➢ A variable is a symbolic name or identifier used to represent a storage
location in computer memory where data can be stored, manipulated,
and retrieved during the execution of a program.
Datatype
return 0; Output??
}
Goto Statement
#include <stdio.h>
int main() {
int num = 5;
if (num == 5) {
goto label;
}
printf("This won't be printed.\n");
label:
printf("This will be printed.\n");
return 0;
}
Looping Statements...
For loop
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
printf("Iteration %d\n", i);
}
return 0;
}
While loop
#include <stdio.h>
int main() {
int count = 1;
while (count <= 5) {
printf("Iteration %d\n", count);
count++;
}
return 0;
}
Do-While loop
#include <stdio.h>
int main() {
int count = 1;
do {
printf("Iteration %d\n", count);
count++;
} while (count <= 5);
return 0;
}
Functions In c
In C, a function is a self-contained block of
code that performs a specific task. Functions
allow you to modularize your code, making it
more organized, readable, and maintainable
Syntax:
return_type function_name(parameters)//Header
{
// Function body
// Code to perform the task
return return_value; // Optional return statement
}
#include <stdio.h>
// Function declaration
int add(int a, int b);
int main() {
int result = add(5, 3); // Calling the add function
printf("Result: %d\n", result);
return 0;
}
// Function definition
int add(int a, int b) {
int sum = a + b;
return sum; // Return the sum as the result of the function
}