0% found this document useful (0 votes)
2 views

C Programming Fundamentals Study Material

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C Programming Fundamentals Study Material

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

C Programming Fundamentals

1. Data Types
C supports various data types, including basic types such as int, float, char, as well as derived types

like arrays, pointers, and structures.

Basic data types include:

- int: for integer values

- float: for floating-point values

- char: for character values

Type modifiers like 'short', 'long', 'signed', and 'unsigned' can alter the size and range of basic data

types.
2. Variables
Variables are containers for storing data values. In C, variables must be declared before they are

used.

Variable declaration syntax: data_type variable_name;

Example: int age;

Variables can be initialized at the time of declaration, e.g., int age = 25;

There are different types of variable scopes:

- Local variables

- Global variables

3. Operations, Expressions, and Statements


C supports several types of operators:

- Arithmetic operators: +, -, *, /, %

- Relational operators: ==, !=, >, <, >=, <=

- Logical operators: &&, ||, !

- Bitwise operators: &, |, ^, ~, <<, >>

Expressions combine variables and operators to produce a value.

Statements in C can be assignment statements, control statements, or function calls.


4. Conditional Statements
Conditional statements allow decision-making in the program flow:

- if statement: Executes a block of code if the condition is true.

- if-else statement: Executes one block if true, another if false.

- switch-case statement: Selects a block of code to execute from multiple choices.

- Ternary operator (?:): A shorthand for 'if-else' conditions.

5. Functions
Functions are blocks of code that perform a specific task. In C, functions must be defined before

use.

Function syntax: return_type function_name(parameter_list) { /* code */ }

Functions can return values or be void (no return).

Example: int add(int a, int b) { return a + b; }


6. Recursive Functions
A recursive function is one that calls itself. It's useful for problems like calculating factorials,

Fibonacci series, and solving puzzles (e.g., Towers of Hanoi).

Example: int factorial(int n) { if (n <= 1) return 1; else return n * factorial(n-1); }

7. Arrays
Arrays are collections of data items of the same type. In C, arrays can be single-dimensional or

multi-dimensional.

- Single-dimensional array: int arr[10];

- Multi-dimensional array: int matrix[3][3];

Arrays are indexed starting from 0.


8. Practical Problems and Sample Code
1. Write a program to calculate the sum of an array of integers.

2. Create a recursive function to find the GCD of two numbers.

3. Implement a switch-case to perform arithmetic operations based on user choice.

4. Write a function to reverse an array.

You might also like