data types, functions
data types, functions
• Definition: Data types define the type of data a variable can hold.
Integer Types:
Character Types:
Floating-Point Types:
• Signed vs Unsigned:
Example:
3. Floating-Point Precision:
Example:
int x = 10;
struct Person {
char name[50];
int age;
};
• Unions: Memory-efficient data type that allows storing different data types in the same
memory location.
Example:
union Data {
int i;
float f;
};
void display();
• Volatile: Tells the compiler that a variable can change at any time.
Example:
Functions in C
Functions are blocks of code designed to perform a specific task. They help in code reusability,
modularity, and readability.
3. Types of Functions:
4. Components of a Function:
• Return Type: The data type of the value the function returns. (void, int, char, etc.)
Syntax:
return_type function_name(parameter_list) {
// Function body
Example:
return a + b;
5. Categories of Functions:
void blinkLED() {
return x * y;
• Pass by Value: Copies the actual value of the argument. Changes do not affect the original
variable.
Example:
• Pass by Reference: Passes the address of the argument, allowing the function to modify the
original variable.
Example:
(*num)++;
7. Recursive Functions:
A function that calls itself to solve smaller instances of a problem. Useful for tasks like factorial
calculation, Fibonacci series, etc.
Example:
int factorial(int n) {
if (n == 0)
return 1;
else
These functions are expanded at the point of call, reducing overhead but increasing code size. Useful
for small, frequently called functions.
Example:
return x * x;
• Keep Functions Short and Focused: Each function should perform a single task.