Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

UNIT – 1

BASICSOFCPROGRAMMING
Problem Solving Methods - Flow Chart, Developing Algorithm - Procedural Programming
(Modular and Structural) - Introduction to programming paradigms – Applications of C
Language - Structure of C program - C programming: Data Types - Constants – Enumeration
Constants - Keywords – Operators: Precedence and Associativity - Expressions – Input / Output
statements, Assignment statements – Decision making statements – Switch statement – Looping
statements – Preprocessor directives - Compilation process.

PROBLEM SOLVING METHODS


Problem-solving in any programming language, including C, involves breaking down a complex
task into smaller, manageable steps and implementing those steps using appropriate techniques.
Here are some problem-solving techniques commonly used in C language:

1. Understanding the Problem: Before you start writing code, make sure you understand the
problem requirements and constraints clearly. Identify the inputs, desired outputs, and any
special conditions to consider.
2. Algorithm Design: Design a step-by-step plan (algorithm) to solve the problem. You can use
techniques like pseudo code or flowcharts to map out the logic before writing the actual code.
3. Decomposition: Break down the problem into smaller sub-problems or tasks. This approach
makes the problem easier to tackle and allows you to focus on one part at a time.
4. Modularization: Divide your C code into smaller, self-contained functions. Each function
should perform a specific task, and you can call these functions whenever needed, making the
code more organized and easier to maintain.
5. Input Validation: Always validate user inputs and handle possible errors or invalid data
gracefully to avoid unexpected behavior or crashes.
6. Looping and Iteration: Use loops (like for, while, do-while) to repeat certain tasks until a
condition is met. They are useful for processing data collections or performing actions multiple
times.
7. Conditional Statements: Employ conditional statements (e.g., if, else if, switch) to make
decisions based on specific conditions, allowing your program to adapt and behave differently
depending on the situation.
8. Arrays and Pointers: Use arrays and pointers effectively to store and manipulate data. They
are particularly useful for managing collections of related elements.
9. Recursion: In C, you can use recursion to solve problems by calling a function within itself.
Recursive algorithms can be elegant and powerful when used appropriately.
10. Data Structures: Choose appropriate data structures (like linked lists, stacks, queues, etc.)
to efficiently organize and manage data based on the problem requirements.
11. Error Handling: Implement error handling mechanisms, like returning error codes or using
exceptions, to deal with unexpected situations and provide meaningful feedback to users.
12. Debugging: Learn how to use C's debugging tools and techniques, like printing intermediate
values or using a debugger, to identify and fix issues in your code.
13. Testing: Always thoroughly test your code with different input scenarios to ensure its
correctness and robustness.
14. Optimization: If required, optimize your code for performance and memory usage, but do
this only after you have a working solution. Premature optimization can make your code harder
to read and maintain.
15. Code Documentation: Add comments and documentation to your code to make it easier for
others (and your future self) to understand the purpose and functionality of different parts of the
program.

FLOW CHART, DEVELOPING ALGORITHM


Flowchart
 It is a graphic representation of a process.
 The process is shown in block-by-block information diagram.
 It is intuitive and easy to understand.
 It is hard to debug errors.
 The solution is showcased in pictorial format.
 It is hard to solve complex problem.
 It costs less time to create a flowchart.
Algorithm
 It is a procedure for solving problems.
 The process is shown in step-by-step instruction.
 It is complex and difficult to understand.
 It is convenient to debug errors.
 The solution is showcased in natural language.
 It is somewhat easier to solve complex problem.
 It costs more time to create an algorithm.

PROCEDURAL PROGRAMMING (MODULAR AND STRUCTURAL)


Modularity: The code can be divided into separate modules or functions to perform specific
tasks, making it easier to maintain and reuse. Standard Data Structures: Procedural programming
makes use of standard data structures such as arrays, lists, and records to store and manipulate
data efficiently.

1. Modular Programming:
Definition: Modular programming focuses on breaking down a program into smaller,
independent modules or functions, each responsible for performing a specific task or
functionality.
Key Concepts:
 Modularity: Encourages dividing a program into smaller, self-contained modules that
can be developed, tested, and maintained independently.
 Abstraction: Allows hiding the implementation details of a module's functionality,
providing a clear interface for interacting with the module.
 Code Reusability: Promotes reuse of modules across different parts of the program or in
different programs, reducing redundancy and improving efficiency.
Advantages:
 Enhances code readability and maintainability by breaking down complex programs into
smaller, more manageable components.
 Facilitates collaborative development by allowing multiple developers to work on
different modules simultaneously.
 Promotes code reuse, leading to faster development cycles and fewer errors.
Example: In C programming, functions serve as modules, where each function encapsulates a
specific task or operation. By organizing related functions into separate modules, modular
programming principles can be applied effectively.
2. Structural Programming:
 Definition: Structural programming emphasizes the use of control structures such as
sequences, loops, and conditionals to control the flow of program execution in a clear and
structured manner.
Key Concepts:
 Sequential Execution: Programs are structured as sequences of instructions that are
executed sequentially, one after the other.
 Selection (Conditional Statements): Allows executing different code blocks based on
specified conditions, using constructs like if-else statements.
 Iteration (Loops): Enables repeating a set of instructions multiple times until a certain
condition is met, using constructs like for, while, and do-while loops.
Advantages:
 Provides clear and logical control flow, making it easier to understand and maintain the
program's behavior.
 Offers fine-grained control over program execution through conditional statements and
loops.
 Facilitates structured error handling and debugging, improving program reliability and
stability.
Example: In C programming, structural programming principles are applied when designing
algorithms using sequences of statements, conditional expressions, and loops to achieve specific
tasks or solve problems.

INTRODUCTION TO PROGRAMMING PARADIGMS

Programming paradigms represent different approaches or styles for writing computer programs.
Each paradigm provides a set of concepts, principles, and techniques for designing, structuring,
and organizing code.
Imperative Programming:
 Definition: Imperative programming focuses on describing a sequence of statements that
change the program's state. Programs are composed of commands that explicitly instruct
the computer on how to perform tasks.
 Key Features: Mutable state, variables, assignment statements, loops, and conditional
statements.
 Example Languages: C, Pascal, BASIC.
Declarative Programming:
 Definition: Declarative programming emphasizes describing the desired outcome or
result without explicitly specifying the steps to achieve it. Programs focus on defining
what needs to be done rather than how to do it.
 Key Features: Emphasis on expressions, functions, and data transformations. Divided
into functional and logic programming paradigms.
 Example Languages: Functional - Haskell, Lisp; Logic - Prolog.
Object-Oriented Programming (OOP):
 Definition: Object-oriented programming organizes code around objects, which are
instances of classes encapsulating data and behavior. It emphasizes concepts like
inheritance, polymorphism, and encapsulation.
 Key Features: Classes, objects, inheritance, polymorphism, encapsulation.
 Example Languages: Java, C++, Python.
Functional Programming:
 Definition: Functional programming treats computation as the evaluation of
mathematical functions. It emphasizes immutability, pure functions, and higher-order
functions.
 Key Features: First-class functions, immutability, recursion, higher-order functions,
lambda expressions.
 Example Languages: Haskell, Lisp, Scala, Erlang.
Logic Programming:
 Definition: Logic programming focuses on defining relations and rules to model
problems as logical predicates. Programs specify the desired outcomes, and the
interpreter infers the steps to achieve them.
 Key Features: Logical inference, pattern matching, unification, backtracking.
 Example Languages: Prolog, Datalog.
Procedural Programming:
 Definition: Procedural programming emphasizes writing procedures or routines that
perform specific tasks. It focuses on the step-by-step execution of instructions to
manipulate data.
 Key Features: Procedures, variables, loops, conditional statements.
 Example Languages: C, Pascal, BASIC.
Aspect-Oriented Programming (AOP):
 Definition: Aspect-oriented programming aims to modularize cross-cutting concerns
such as logging, security, and error handling. It achieves this by separating such concerns
from the main application logic.
 Key Features: Aspects, pointcuts, advice, weaving.
 Example Languages: AspectJ, Spring AOP.

APPLICATIONS OF C LANGUAGE

C programming language, being one of the oldest and most widely used programming languages,
finds applications in various domains. Here are some common applications of C:
1. System Programming: C is commonly used for system programming tasks such as
developing operating systems, device drivers, firmware, and low-level libraries. Its close-
to-hardware nature and ability to manipulate memory efficiently make it suitable for
these purposes.
2. Embedded Systems: C is extensively used in embedded systems programming for
microcontrollers, sensors, and other embedded devices. Its efficiency in terms of memory
usage and execution speed makes it well-suited for resource-constrained environments.
3. Compilers and Interpreters: Many compilers and interpreters for other programming
languages are written in C. Its portability and ability to generate efficient machine code
contribute to its popularity in this domain.
4. Application Software: While C is not as commonly used for developing application
software compared to higher-level languages like Java or Python, it is still employed in
performance-critical applications such as gaming engines, graphics software, and real-
time applications.
5. Databases: C is used in developing database management systems (DBMS) and database
engines due to its efficiency in handling data structures and memory management.
Projects like SQLite, which is a lightweight and self-contained SQL database engine, are
written in C.
6. Networking: C is used for developing network-based applications such as web servers,
network protocols, and communication software. Its ability to interact directly with
system resources and sockets makes it suitable for implementing networking
functionalities.
7. Operating Systems: C has been extensively used in the development of operating
systems such as Unix, Linux, and Windows. Many parts of these operating systems,
including the kernel and core utilities, are written in C due to its efficiency and low-level
control.
8. Compilers and Tools: C is used for developing compilers, debuggers, code analyzers,
and other software development tools. Its ability to manipulate memory and perform low-
level operations makes it suitable for implementing such tools.
9. High-Performance Computing: C is commonly used in scientific computing and high-
performance computing (HPC) applications where performance is critical. Libraries such
as OpenMP and MPI are commonly used with C for parallel computing tasks.
10. Security Software: C is used for developing security software such as antivirus
programs, encryption libraries, and network security tools. Its low-level control and
efficient memory handling are essential for implementing security-related algorithms and
protocols.

STRUCTURE OF C PROGRAM
There are 6 basic sections responsible for the proper execution of a program. Sections are
mentioned below:
1. Documentation
2. Preprocessor Section
3. Definition
4. Global Declaration
5. Main() Function
6. Sub Programs

1. Documentation
 This section consists of the description of the program, the name of the program, and the
creation date and time of the program. It is specified at the start of the program in the
form of comments. Documentation can be represented as:
// description, name of the program, programmer name, date, time etc.
or
/*
description, name of the program, programmer name, date, time etc.
*/
 Anything written as comments will be treated as documentation of the program and this
will not interfere with the given code. Basically, it gives an overview to the reader of the
program.
2. Preprocessor Section
 All the header files of the program will be declared in the preprocessor section of the
program. Header files help us to access other’s improved code into our code. A copy of
these multiple files is inserted into our program before the process of compilation.
Example:
#include<stdio.h>
#include<math.h>
3. Definition
 Preprocessors are the programs that process our source code before the process of
compilation. There are multiple steps which are involved in the writing and execution of
the program. Preprocessor directives start with the ‘#’ symbol. The #define preprocessor
is used to create a constant throughout the program. Whenever this name is encountered
by the compiler, it is replaced by the actual piece of defined code.
Example:
#define long long ll

4. Global Declaration
 The global declaration section contains global variables, function declaration, and static
variables. Variables and functions which are declared in this scope can be used anywhere
in the program.
Example:
int num = 18;
5. Main() Function
 Every C program must have a main function. The main() function of the program is
written in this section. Operations like declaration and execution are performed inside the
curly braces of the main program.
 The return type of the main() function can be int as well as void too. void() main tells the
compiler that the program will not return any value. The int main() tells the compiler that
the program will return an integer value.
Example:
void main()
or
int main()
6. Sub Programs
 User-defined functions are called in this section of the program. The control of the
program is shifted to the called function whenever they are called from the main or
outside the main() function. These are specified as per the requirements of the
programmer.
Example:
int sum(int x, int y)
{
return x+y;
}
Structure of C Program with example
Example: Below C program to find the sum of 2 numbers:
C
// Documentation
/**
* file: sum.c
* author: you
* description: program to find sum.
*/
// Link
#include <stdio.h>

// Definition
#define X 20

// Global Declaration
int sum(int y);

// Main() Function
int main(void)
{
int y = 55;
printf("Sum: %d", sum(y));
return 0;
}

// Subprogram
int sum(int y)
{
return y + X;
}
Output
Sum: 75
DATA TYPES

Integer Data Type


 The integer data type in C is used to store the integer numbers(any number including
positive, negative and zero without decimal part). Octal values, hexadecimal values, and
decimal values can be stored in int data type in C.
 Range: -2,147,483,648 to 2,147,483,647
 Size: 4 bytes
 Format Specifier: %d
Syntax of Integer
 We use int keyword to declare the integer variable: int var_name; The integer data type
can also be used as
 unsigned int: Unsigned int data type in C is used to store the data values from zero to
positive numbers but it can’t store negative values like signed int.
 short int: It is lesser in size than the int by 2 bytes so can only store values from -32,768
to 32,767.
 long int: Larger version of the int data type so can store values greater than int.
 unsigned short int: Similar in relationship with short int as unsigned int with int.
Example:
#include <stdio.h>
int main()
{
// Integer value with positive data.
int a = 9;
// integer value with negative data.
int b = -9;
// U or u is Used for Unsigned int in C.
int c = 89U;
// L or l is used for long int in C.
long int d = 99998L;
printf("Integer value with positive data: %d\n", a);
printf("Integer value with negative data: %d\n", b);
printf("Integer value with an unsigned int data: %u\n",c);
printf("Integer value with an long int data: %ld", d);
return 0;
}
Output:
Integer value with positive data: 9
Integer value with negative data: -9
Integer value with an unsigned int data: 89
Integer value with an long int data: 99998
Character Data Type
 Character data type allows its variable to store only a single character. The size of the
character is 1 byte. It is the most basic data type in C. It stores a single character and
requires a single byte of memory in almost all compilers.
 Range: (-128 to 127) or (0 to 255)
 Size: 1 byte
 Format Specifier: %c
Syntax of char
 The char keyword is used to declare the variable of character type: char var_name;
Example:
#include <stdio.h>
int main()
{
char a = 'a';
char c;
printf("Value of a: %c\n", a);
a++;
printf("Value of a after increment is: %c\n", a);
// c is assigned ASCII values
// which corresponds to the
// character 'c'
// a-->97 b-->98 c-->99
// here c will be printed
c = 99;
printf("Value of c: %c", c);
return 0;
}
Output:
Value of a: a
Value of a after increment is: b
Value of c: c
Float Data Type
 In C programming float data type is used to store floating-point values. Float in C is used
to store decimal and exponential values. It is used to store decimal numbers (numbers
with floating point values) with single precision.
 Range: 1.2E-38 to 3.4E+38
 Size: 4 bytes
 Format Specifier: %f
Syntax of float
 The float keyword is used to declare the variable as a floating point: float var_name;
Example:
#include <stdio.h>
int main()
{
float a = 9.0f;
float b = 2.5f;

// 2x10^-4
float c = 2E-4f;
printf("%f\n", a);
printf("%f\n", b);
printf("%f", c);

return 0;
}
Output:
9.000000
2.500000
0.000200
Double Data Type
 A Double data type in C is used to store decimal numbers (numbers with floating point
values) with double precision. It is used to define numeric values which hold numbers
with decimal values in C.
 The double data type is basically a precision sort of data type that is capable of holding
64 bits of decimal numbers or floating points.
 Since double has more precision as compared to that float then it is much more obvious
that it occupies twice the memory occupied by the floating-point type.
 It can easily accommodate about 16 to 17 digits after or before a decimal point.
 Range: 1.7E-308 to 1.7E+308
 Size: 8 bytes
 Format Specifier: %lf
Syntax of Double
 The variable can be declared as double precision floating point using the double
keyword: double var_name;

// C Program to demonstrate
// use of double data type
#include <stdio.h>

int main()
{
double a = 123123123.00;
double b = 12.293123;
double c = 2312312312.123123;

printf("%lf\n", a);

printf("%lf\n", b);

printf("%lf", c);
return 0;
}
Output:
123123123.000000
12.293123
2312312312.123123

Void Data Type


 The void data type in C is used to specify that no value is present. It does not provide a
result value to its caller. It has no values and no operations. It is used to represent
nothing. Void is used in multiple ways as function return type, function arguments as
void, and pointers to void.
Syntax:
// function return type void
void exit(int check);
// Function without any parameter can accept void.
int print(void);
// memory allocation function which
// returns a pointer to void.
void *malloc (size_t size);
Example:
#include <stdio.h>
int main()
{
int val = 30;
void* ptr = &val;
printf("%d", *(int*)ptr);
return 0;
}
Output: 30
Size of Data Types in C
 The size of the data types in C is dependent on the size of the architecture, so we cannot
define the universal size of the data types. For that, the C language provides the sizeof()
operator to check the size of the data types.
Example
#include <stdio.h>
int main()
{
int size_of_int = sizeof(int);
int size_of_char = sizeof(char);
int size_of_float = sizeof(float);
int size_of_double = sizeof(double);

printf("The size of int data type : %d\n", size_of_int);


printf("The size of char data type : %d\n",size_of_char);
printf("The size of float data type : %d\n",size_of_float);
printf("The size of double data type : %d",size_of_double);
return 0;
}
Output:
The size of int data type : 4
The size of char data type : 1
The size of float data type : 4
The size of double data type : 8
CONSTANTS

Syntax to Define Constant

 const data_type var_name = value;

Integer Constants:
 Integer constants represent whole numbers without any fractional part.
 Examples: 10, -5, 1000, etc.
 Integer constants can be represented in decimal, octal, or hexadecimal formats.
1. Decimal format: 10, -20
2. Octal format (prefixed with '0'): 077, -010
3. Hexadecimal format (prefixed with '0x' or '0X'): 0xFF, -0x1A
Floating-Point Constants:
 Floating-point constants represent numbers with fractional parts.
 Examples: 3.14, -0.005, 100.0, etc.
 Floating-point constants are represented in decimal format and may include an exponent
part.
1. Decimal format: 3.14, -0.005
2. Exponential notation: 1.23e-5, 1.5E2
Character Constants:
 Character constants represent individual characters enclosed within single quotes.
 Examples: 'A', 'b', '5', '$', etc.
 A character constant represents an ASCII value of the character.
 char ch = 'A';
String Constants:
 String constants represent sequences of characters enclosed within double quotes.
 Examples: "Hello", "C Programming", "1234", etc.
 String constants are represented as arrays of characters with a null-terminating character
('\0') at the end.
 char str[] = "Hello";
Symbolic Constants:
 Symbolic constants are identifiers that represent fixed values and are defined using the
#define preprocessor directive.
#define PI 3.14159
#define MAX_LENGTH 100

ENUMERATION CONSTANTS
Enumeration Declaration:
 Enumeration constants are declared using the enum keyword followed by the name of the
enumeration.
 Inside the curly braces, you specify a list of named constants separated by commas.
enum Color {
RED,
GREEN,
BLUE
};
Enumeration Constants:
 Each constant within an enumeration gets an integer value starting from 0 for the first
constant and incrementing by 1 for subsequent constants.
 You can also explicitly assign integer values to enumeration constants.
NO enum Direction {
NORTH = 1,
SOUTH,
EAST,
WEST
};
Using Enumeration Constants:
 Enumeration constants are typically used to declare variables, function parameters, or
function return types.
enum Color c = RED;
enum Direction d = EAST;
Size of Enumeration Constants:
 By default, enumeration constants are of type int, and their size depends on the size of an
integer on the particular platform.
 You can use the sizeof operator to determine the size of an enumeration constant.
printf("Size of enum Color: %lu bytes\n", sizeof(enum Color));
 In C++, enumeration constants can be scoped using the enum class keyword to avoid
naming conflicts.
enum class Weekday {
MONDAY,
TUESDAY,
WEDNESDAY
};
Example:
#include <stdio.h>
// Define an enumeration for colors
enum Color {
RED,
GREEN,
BLUE
};

// Define an enumeration with explicitly assigned values


enum Direction {
NORTH = 1,
SOUTH,
EAST,
WEST
};

int main() {
enum Color c = RED;
enum Direction d = EAST;
printf("Color: %d\n", c); // Output: 0
printf("Direction: %d\n", d); // Output: 3
printf("Size of enum Color: %lu bytes\n", sizeof(enum Color)); // Output: 4 bytes
return 0;
}
KEYWORDS
Keywords in C are reserved words that have predefined meanings and cannot be used as
identifiers (such as variable names, function names, etc.) in the program. These keywords are an
integral part of the C language syntax and serve specific purposes within the language. Here's a
list of keywords in C:

 auto: Specifies automatic storage duration for variables declared within a block.
 break: Terminates the execution of the nearest enclosing loop or switch statement.
 case: Defines a label within a switch statement.
 char: Declares a character data type.
 const: Specifies that a variable's value cannot be changed.
 continue: Skips the remaining code in the loop and proceeds to the next iteration.
 default: Specifies the default case within a switch statement.
 do: Introduces a do-while loop.
 double: Declares a double-precision floating-point data type.
 else: Introduces the else part of an if-else statement.
 enum: Declares an enumeration data type.
 extern: Declares a variable or function as externally defined.
 float: Declares a single-precision floating-point data type.
 for: Introduces a for loop.
 goto: Transfers control to a labeled statement.
 if: Introduces an if statement.
 int: Declares an integer data type.
 long: Declares a long integer data type.
 register: Suggests that a variable be stored in a CPU register.
 return: Returns a value from a function.
 short: Declares a short integer data type.
 signed: Declares a signed integer data type.
 sizeof: Returns the size of a data type or variable.
 static: Specifies static storage duration for variables.
 struct: Declares a structure data type.
 switch: Introduces a switch statement.
 typedef: Defines a new data type using an existing data type.
 union: Declares a union data type.
 unsigned: Declares an unsigned integer data type.
 void: Specifies that a function does not return a value or declares a pointer to void.
 volatile: Specifies that a variable may be changed externally.
 while: Introduces a while loop.

OPERATORS: PRECEDENCE AND ASSOCIATIVITY


 The concept of operator precedence and associativity in C helps in determining which
operators will be given priority when there are multiple operators in the expression. It is very
common to have multiple operators in C language and the compiler first evaluates the operater
with higher precedence. It helps to maintain the ambiguity of the expression and helps us in
avoiding unnecessary use of parenthesis.
 In this article, we will discuss operator precedence, operator associativity, and precedence
table according to which the priority of the operators in expression is decided in C language.

Operator Precedence and Associativity Table


The following tables list the C operator precedence from highest to lowest and the associativity
for each of the operators:
Precedence Operator Description Associativity

() Parentheses (function call)


[] Array Subscript (Square Brackets)
1 . Dot Operator Left-to-Right
-> Structure Pointer Operator
++ , — Postfix increment, decrement
++ / — Prefix increment, decrement
+/– Unary plus, minus
2 !,~ Logical NOT, Bitwise complement Right-to-Left
(type) Cast Operator
* Dereference Operator
& Addressof Operator
sizeof Determine size in bytes
3 *,/,% Multiplication, division, modulus Left-to-Right
4 +/- Addition, subtraction Left-to-Right
5 << , >> Bitwise shift left, Bitwise shift right Left-to-Right
< , <= Relational less than, less than or equal to
6 Relational greater than, greater than or equal Left-to-Right
> , >=
to
7 == , != Relational is equal to, is not equal to Left-to-Right
8 & Bitwise AND Left-to-Right
9 ^ Bitwise exclusive OR Left-to-Right
10 | Bitwise inclusive OR Left-to-Right
11 && Logical AND Left-to-Right
12 || Logical OR Left-to-Right
13 ?: Ternary conditional Right-to-Left
= Assignment
+= , -= Addition, subtraction assignment
*= , /= Multiplication, division assignment
14 Right-to-Left
%= , &= Modulus, bitwise AND assignment
^= , |= Bitwise exclusive, inclusive OR assignment
<<=, >>= Bitwise shift left, right assignment
15 , comma (expression separator) Left-to-Right

EXPRESSION
 Constant expressions: Constant Expressions consists of only constant values. A constant
value is one that doesn’t change.
Examples:
5, 10 + 5 / 6.0, 'x’
 Integral expressions: Integral Expressions are those which produce integer results after
implementing all the automatic and explicit type conversions.
Examples:
x, x * y, x + int( 5.0)
where x and y are integer variables.
 Floating expressions: Float Expressions are which produce floating point results after
implementing all the automatic and explicit type conversions.
Examples:
x + y, 10.75
where x and y are floating point variables.
 Relational expressions: Relational Expressions yield results of type bool which takes a
value true or false. When arithmetic expressions are used on either side of a relational
operator, they will be evaluated first and then the results compared.
 Relational expressions are also known as Boolean expressions.
Examples:
x <= y, x + y > 2
 Logical expressions: Logical Expressions combine two or more relational expressions
and roduces bool type results.
Examples:
x > y && x == 10, x == 10 || y == 5
 Pointer expressions: Pointer Expressions produce address values.
Examples:
&x, ptr, ptr++
where x is a variable and ptr is a pointer.
 Bitwise expressions: Bitwise Expressions are used to manipulate data at bit level. They
are basically used for testing or shifting bits.
Examples:
x << 3
shifts three bit position to left
y >> 1
shifts one bit position to right.
Shift operators are often used for multiplication and division by powers of two.

INPUT / OUTPUT STATEMENTS, ASSIGNMENT STATEMENTS


Output Statements:
 The printf() function is used to print formatted output to the standard output device
(usually the console).
 It takes a format string as its first argument, which can contain placeholders for variables
and values to be printed.
Example:
int num = 10;
printf("The value of num is: %d\n", num);
 In the format string, %d is a placeholder for an integer value, and \n represents a newline
character.
Input Statements:
 The scanf() function is used to read formatted input from the standard input device
(usually the keyboard).
 It takes format specifiers as its subsequent arguments, which specify the types of values
to be read and the variables to store them in.
Example:
int num;
printf("Enter a number: ");
scanf("%d", &num);
 In the format string, %d specifies that an integer value is expected, and &num is the
memory address of the variable num where the input value will be stored.
Assignment Statement
 An assignment statement in C is used to assign a value to a variable. It consists of the
variable on the left-hand side and the value or expression on the right-hand side,
separated by the assignment operator =.
Example:
int x; // Declaration of variable 'x'
x = 10; // Assignment statement: Assigning the value 10 to variable 'x'
 In this example, x is a variable of type int, and x = 10; is the assignment statement. It
assigns the value 10 to the variable x.

Decision making statements


Switch statement
Looping statements
Preprocessor directives
Compilation process.

You might also like