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

Fundamentals of C

C is a general-purpose, procedural programming language developed in 1972, widely used for system and application development. Key components of C programming include data types, operators, control statements, functions, arrays, pointers, and file handling. A basic C program structure consists of preprocessor directives, a main function, a body, and a return statement.

Uploaded by

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

Fundamentals of C

C is a general-purpose, procedural programming language developed in 1972, widely used for system and application development. Key components of C programming include data types, operators, control statements, functions, arrays, pointers, and file handling. A basic C program structure consists of preprocessor directives, a main function, a body, and a return statement.

Uploaded by

kalakaardost17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Fundamentals of C Programming

1. Introduction
C is a general-purpose, procedural programming language developed by Dennis Ritchie in
1972 at Bell Labs. It is widely used for system programming, embedded systems, and
application development.

2. Basics of C
C programs use alphabets (A-Z, a-z), digits (0-9), and special symbols (+, -, *, /, %, { }, ; etc.).
The smallest units in a C program include:

• Keywords (e.g., int, return, if, else)

• Identifiers (variable, function names)

• Constants (e.g., 10, 3.14, 'A')

• Operators (e.g., +, -, *, /, =, &&, ||)

• Special Characters (e.g., { } ; , () [])

3. Structure of a C Program
A basic C program consists of:

1. Preprocessor Directives (#include <stdio.h>)

2. Main Function (int main() { })

3. Body (variable declaration, logic, functions)

4. Return Statement (return 0;)

Example:

#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}

4. Data Types in C
C has different data types categorized as:

• Basic Data Types: int, float, char, double

• Derived Data Types: array, pointer, structure, union


• User-Defined Data Types: typedef, enum, struct

5. Operators in C
Operators perform operations on variables and values. Some important types are:

• Arithmetic Operators: +, -, *, /, %

• Relational Operators: ==, !=, >, <, >=, <=

• Logical Operators: &&, ||, !

• Assignment Operators: =, +=, -=, *=, /=

• Increment/Decrement Operators: ++, --

6. Control Statements
Control flow determines the execution sequence of a program.

Conditional Statements:
Example of if-else statement:

if (a > b) {
printf("A is greater");
} else {
printf("B is greater");
}

Looping Statements:
Example of for loop:

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


printf("%d ", i);
}

7. Functions in C
Functions help in reusing code. Example:

int add(int a, int b) {


return a + b;
}
int main() {
int sum = add(5, 3);
printf("Sum: %d", sum);
return 0;
}
8. Arrays in C
Arrays store multiple values of the same data type. Example:

int numbers[5] = {1, 2, 3, 4, 5};


printf("%d", numbers[2]); // Output: 3

9. Pointers in C
Pointers store memory addresses. Example:

int a = 10;
int *ptr = &a;
printf("%d", *ptr); // Output: 10

10. File Handling in C


Example of writing to a file:

FILE *file = fopen("data.txt", "w");


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

You might also like