0% found this document useful (0 votes)
2 views3 pages

C Programming Lecture Notes

Uploaded by

edwinkerubo070
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

C Programming Lecture Notes

Uploaded by

edwinkerubo070
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Programming Lecture Notes with Examples

Introduction to C Programming

C is a general-purpose programming language developed by Dennis Ritchie. It is widely used for system
programming, software development, and embedded systems.

Structure of a C Program
Example:
#include <stdio.h>

int main() {
printf("Hello World");
return 0;
}

Variables and Data Types


Example:
#include <stdio.h>

int main() {
int age = 20;
float marks = 85.5;
char grade = 'A';

printf("%d", age);
return 0;
}

Operators in C

Arithmetic Operators: +, -, *, /, %
Comparison Operators: ==, !=, >, <
Logical Operators: &&, ||, !

Conditional Statements
Example:
#include <stdio.h>

int main() {
int number = 10;

if(number > 0) {
printf("Positive Number");
} else {
printf("Negative Number");
}

return 0;
}
Loops in C
For Loop Example:
#include <stdio.h>

int main() {
int i;

for(i = 1; i <= 5; i++) {


printf("%d\n", i);
}

return 0;
}

Functions in C
Example:
#include <stdio.h>

int sum(int a, int b) {


return a + b;
}

int main() {
int answer = sum(5, 3);
printf("%d", answer);

return 0;
}

Arrays in C
Example:
#include <stdio.h>

int main() {
int numbers[3] = {10, 20, 30};

printf("%d", numbers[1]);

return 0;
}

Pointers in C
Example:
#include <stdio.h>

int main() {
int x = 10;
int *ptr = &x;

printf("%d", *ptr);

return 0;
}

File Handling
Example:
#include <stdio.h>

int main() {
FILE *file;

file = fopen("[Link]", "w");


fprintf(file, "Hello File");
fclose(file);

return 0;
}

You might also like