Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

C Language

INTRODUCTION OF C
LANGUAGE
History of C language
• C is a general-purpose programming
language that was developed in the
early 1970s by Dennis Ritchie at
Bell Labs.
• It was originally designed as a
system programming language for
the Unix operating system.
Advantages of C language
• Efficiency: C is known for its high performance and efficiency. It allows low-level access to
memory and provides direct control over hardware, making it suitable for system-level
programming and resource-constrained environments.
• Portability: C is a widely supported language, and programs written in C can be compiled and run
on different platforms with minimal modifications. This portability makes it a popular choice for
developing cross-platform applications.
• Flexibility: C offers a wide range of features and allows programmers to have fine-grained control
over the code. It supports both procedural and object-oriented programming paradigms, enabling
developers to choose the most suitable approach for their projects.
• Extensibility: C supports the use of libraries and allows for the creation of reusable code modules.
This promotes code reuse, simplifies development, and enhances productivity.
• Legacy Code Compatibility: C has been around for several decades and has a large codebase.
Many existing systems and libraries are written in C, making it necessary to know the language to
maintain and integrate with legacy codebases.
Variables and Data Types
Declaring Variables

• In C, variables must be declared before they can be used.


• The declaration specifies the name and data type of the
variable.
• Syntax: data_type variable_name;

Data Types
• C supports various data types, including int, float, char,
double, void.

Assigning Values

• After declaring a variable, you can assign a value to it using


the assignment operator (=)
• Syntax: variable_name = value;
Variables and Data Types

Using Variables

• Once a variable is declared and assigned a value, it can


be used in expressions and statements.
• Example: int x = 5; int y = 3; int sum = x + y;

Printing Variables

• You can print the value of a variable using the printf


function.
• Syntax: printf("%data_type", variable_name);
• Example: printf("The sum is %d", sum);
Basic structure of C program
OTHER NECESSARY
MAIN FUNCTION COMPONENTS
The main function is the entry point of a C • Preprocessor Directives: These are lines of code that start
with a '#' symbol and are used to include header files and
program. It is the starting point of program perform other preprocessing tasks.
execution. All C programs must have a main
function, and it is defined as follows: • Function Declarations: These are statements that declare
the types and names of functions used in the program.
int main() { • Variable Declarations: These are statements that declare
the types and names of variables used in the program.
// Code goes here
• Statements: These are the actual instructions or actions that
return 0; the program performs.

• Comments: These are lines of code that are ignored by the


} compiler and are used to add notes or explanations to the
code.
Basic structure of C program

PRINTF() SCANF() GETCHAR() PUTCHAR()


The printf() function The scanf() function is The getchar() function The putchar() function
is used to write used to read formatted is used to read a single is used to write a
formatted output to input from the character from the single character to the
the console. It takes a console. It takes a console. It does not console. It takes a
format string as an format string as an
argument, which argument, which require a format string character as an
specifies the format of specifies the format of and returns the ASCII argument and does not
the output. For the input. For value of the character. require a format string.
example, to print a example, to read an
string, you can use the integer, you can use
%s format specifier. the %d format
specifier.
Operators in C
ARITHMETIC RELATIONAL LOGICAL ASSIGNMENT
OPERATORS OPERATORS OPERATORS OPERATORS
• Addition (+) • Equal to (==)
•AND (&&) •Assign (=)
• Subtraction (-) • Not equal to (!=)
•OR (||) •Add and assign (+=)
• Multiplication (*) • Greater than (>) •NOT (!) •Subtract and assign (-=)
• Division (/) • Less than (<) •Multiply and assign (*=)
• Modulus (%) • Greater than or equal •Divide and assign (/=)
to (>=)
•Modulus and assign (%=)
• Less than or equal to
(<=)
Operators in C
INCREMENT AND BITWISE CONDITIONAL
DECREMENT OPERATORS OPERATOR
OPERATORS
• Increment (++) • Bitwise AND (&)
• Ternary operator (?:)
• Decrement (--) • Bitwise OR (|)
• Bitwise XOR (^)
• Bitwise NOT (~)
• Left shift (<<)
• Right shift (>>)
SUBMITTED BY
HARRY SHARMA

You might also like