You are on page 1of 20

C Introduction

• Introduction to C
• C Features
• Uses of C
• Structure of C program
Agenda • Variables
• Data Types
• Operators

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
C Introduction
• Developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories.
• Known as Mother Language as it’s a base for other programming languages.
• Used to develop operating systems, databases, application etc.
• Most popular system programming language.
• UNIX operating system was totally written in C.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
C Features
• Simple and Efficient: Syntax style of implementing C language is very simple and easy.
• Portable: Programs made in it can be run on different machines.
• Function-Rich Library: Having a rich number of libraries with built-in functions.
• Memory Management: Supports Dynamic Memory Management (DMA).
• Pointers: With C pointers, we can directly interact with memory.
• Structured Language: Breaks the code into different parts using functions and stored
in the form of libraries for the reusability.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Uses of C Language
• Computational and graphical methods.
• Applications using graphical user interfaces.
• Browsers on the internet.
• Banking.
• Compilers.
• Cloud Computing and distributed systems.
• Integrated software libraries for enterprises.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Structure of a C Program

Documentation Section

Preprocessor Section

Definition Section

Global Declaration

Main Function

User-Defined Functions

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Demo
Creating a Hello World Program in C

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Variables and Literals
A name was given to a memory location. It is the basic unit of storage in a program.

Rules for naming a variable:

i) A variable name can only have alphabets, numbers, and the underscore _.
ii) A variable name cannot begin with a number.
iii) It is a preferred practice to begin variable names with a lowercase character. For
example, age is preferable to Age.
iv) No whitespace is allowed in the variable name.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Variables and Literals
• A variable name cannot be a keyword.
• For example, int is a keyword that is used to denote
integers. Int age = 25; // age is 25
age = 23; // age is 23
• Can start with an underscore. However, it's not
considered a good practice. Integer: 1,2 3,4...
Floating-point: 2.4,6.0,5.6 ..
• Literals are data used for representing fixed values. They
Character: 'a','b','U','9'..
can be used directly in the code. For String: "age","" ," " ..
example: 1, 2.5, 'c' etc.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Variables Scope
A Scope is region of the program and broadly speaking there are three places, where
variables can be declared :
• Inside a function or a block which is called local variables.
• In the definition of function parameters which is called formal parameters.
• Outside of all functions which is called global variables.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Types of Variables

Variables

Local Global Static Automatic External


Variables Variables Variables Variables Variables

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Type of Variables
On the basis of scope, there are two types of variables:
Local Variables:
• Defined inside a function or a code block.
• Scope of these variables remain limited to block in which they are declared.
Global Variables:
• Declared outside the function or a block of code.
• We can access these variables anywhere in the program after it is declared.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Type of Variables
On the basis of storage classes, there are two types of variables:
Static Variables:
• Defined using a static keyword.
• Scope depends upon the region where they are declared – can be local or global.
Automatic Variables:
• By default, all the local variables are automatic variables.
• Scope is local and it’s default value is a garbage value.
External Variables:
• Can be shared between multiple C files.
• Scope is global and declared using extern keyword.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Demo
Variable Scope

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Data types
• Different sizes and values that can be stored in the variable that is made as per
convenience and circumstances to cover up all test cases.
• Can be categorized into four types:

Data types

Basic Derived Enumeration Void

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Data types

Type Data Type


Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union


Enumeration Data Type enum
Void Data Type void

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Basic Data types
• Basic data types are integer-based and floating-point based.
• Supports both signed and unsigned literals.
• Memory size of basic data types may change according to 32 or 64 bit operating system.

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Basic Data types
Data Type Meaning Size (in Bytes)
int Integer 2 or 4
float Floating-point 4
double Double Floating-point 8
char Character 1
short int Short Integer 2
long int Long Integer 4
void Empty 0

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Operators in C++
• Operator are the symbols that are used to perform operations.
• For example: +, -, *, / etc.
• Can be categorized into following groups:

Operators

Arithmetic Relational Logical Bitwise Assignment

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Precedence of Operators
category Operators Associativity
Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & sizeof Right to left
Multiplicative */% Left to right
Additive +- Right to left
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == !=/td> Right to left
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
THANKS
Any Questions?

Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.

You might also like