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

Chapter 13 Datatypes Variables

Uploaded by

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

Chapter 13 Datatypes Variables

Uploaded by

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

Variables, Data types

SURESH TECHS
CHAPTER 13 C PROGRAMMING COURSE
NOTE
ఈ చాప్ట ర్ లో కకుంచ ుం ఎకకువ discuss చేస్ా తన . కతబట్టట, మొదట్ట
స్తరి అన్నీ అర్ధుం అయ్యే అవకతశుం లేద .

ఒకవేళ అర్ధుం కతకపో య్నా ప్రతాలేద , next lessons


చూస్ా నీప్ుడు automatic గత అర్ధుం అవుతాయ్. కతన్న, ఈ chapter
లో చెప్పిన విషయాలక గుర్్ాుంట్ే మాత్రుం మీర్్ ఎట్ువుంట్ట
programming ఐనా కూడా easy గత నేర్్ుకోగలర్్.
7 చేప్ల కథ

నా బంగారు పుట్టలో
వేలు పెడితే కుట్టనా
7 చేప్ల కథ
Sometimes we will stop!

నా బంగారు పుట్ట లో
వేలు పెడితే కుట్ట నా

Sometimes we will discuss deep concepts


Data types, Variables
Childhood days (చినీనాట్ట రోజులక)

pot-a pot-b
pot-a = 10
pot-b = 30
Variable
• It is used to store data
• It’s value can be changed at any
time

a b
కొన్నన రోజులు (Research)

కొన్నన రోజుల తరువాత

1. 10 bores are not working – int bores = 10;

2. Pass percentage of school Let’s operate our


students are 30.26 kingdom

Father
3. Fight with king “SURBALI”

Dennis Ritchie

నాన్న నాకు కుంచ ం


సమయం ఇవ్వండి
SURBALI
• A program can have different types of data
• 10 int
• 30.26 float, double
Realization
• SURBALI char

• Discovered types for data and named them as data types


Types of data types
void
char
double union Data types
int float enum
functions typedef Primary Secondary
structure Data types Data types
array pointer
Alpha User
Numeric Derived
numeric defined

Integer Decimal Character Data type defines type of data and


size of data
Small Math
Mass/Weight of the Earth?
• 500
• 5*100 5970,000,000,000,000,000,000,000 kg
• 5*10^2 597*10^22
• 5e2
5.97*10^24
• 80000 5.97e24
• 8*10^4
• 0.8*10^5 mantissa e exponent
• 0.8e5 Real number expressed
in decimal notation or
Integer number with Letter e separating mantissa
an optional plus or and exponent can be written
an integer minus sign lowercase or uppercase
What is memory?
Registers usually consist of a Processor(cup) – i3, i5, i7
small amount(32 bit, 64 bit) of
fast storage

New laptop

ROM (4mb, 8mb)


RAM (4gb, 8gb, 16gb,
32gb)

Compiler
printfprograms.exe printfprograms.c HARD DISK (500gb,1tb,2tb)
/printfprograms.out
• You have S, U characters and you have to come up with different
combinations with size(length) of 2
• SU
• US
Small test
• UU
• SS
• A bit is a binary(0 or 1) digit.
• A bit can hold only one of two values: 0 or 1
• A bit (short
Bit?for binary digit) is the smallest unit of data in a
computer
• 00
• 01
• 10 Combinations(0 & 1 – size of 2 bits)
• 11
• 000

2^3 = 8 2^2 = 4
00
• 001 • 01

• 010 10
Combinations(0 & 1 – size of 3 bits)
• 11
• 100
• 101 8 bits(01001101) - 1 byte
• 110
• 011 2^8 = 2*2*2*2*2*2*2*2 = 256
• 111 With 1 byte, we can represent 256 numbers
data type defines More the memory,
size of the data more the size😍😍
int a = 10;

• 1 byte – 8 bits • 2^8 = 256

• 2 bytes – 16 bits • 2^16 = 65,536

• 4 bytes –Memory
32 bits • 2^32= 4,29,49,67,296

Small - Rs. 10 Medium – Rs. 20 Large - Rs. 40


0 10 90 00110100011010110
0 30 60 00110100011010111
40 00110100011010101

60 00110100011010001
• Data type defines type of data and size of data
• Size is nothing but memory – how much data that variable can hold
What is data type?
Basic data types(most used)

Type Size(bytes) Range Format specifier


int 2/4 -2,14,74,83,648 to 2,14,74,83,647 %d, %i
char 1 -128 to 127 %c
float 4 3.4E +/-38 %f
double 8 1.7E +/-308 %lf

https://opensource.apple.com/source/xnu/xnu-792.13.8/EXTERNAL_HEADERS/ppc/limits.h.auto.html

https://opensource.apple.com/source/Libm/Libm-47.1/i386.subproj/float.h.auto.html
• Used to represent whole numbers that can have zero, positive and
negative values but no decimal values
• We use int for declaring a integer variable
• int a;
int
• We can declare multiple variables at once
• int a,b,c;
• Used to represent numbers with decimal points
• Used when more precision is required
float, double
Difference between Float and Double

Float Double
4 bytes – 32 bits 8 bytes – 64 bits
Used to represent decimal values( ex: 7.987) Used to represent decimal values( ex: 8.182)
Single precision data type(6 decimal places) Double precision data type(15 decimal places)
Ex: 7.879888 Ex: 8.182191283871221
It is faster It is slow as it works with very large values
• sizeof(data type)
• sizeof(variable)
Size of data type
• int noOfBores = 10;
• float passPercentage = 30.26;
• What about SURBALI 🤣🤣?

SURBALI
How do we represent a Collection of characters is
character? called a string
• It is used to store single character values

• C uses achar
character encoding
data type scheme called ASCII to represent
characters or special characters

• ASCII – American Standard Code for Information Interchange


• Each character has an ASCII value associated with it.

• The keyword “char” is


char data type used to declare the char data type.

• The format specifier for this data type is "%c“


• char data type is used to store characters/letters
• Underneath C stores integer numbers instead of characters
Storing characters and letters
• Note: In order to represent characters, the computer has to map each
integer with a corresponding character using a numerical code. The
most common numerical code is ASCII, which stands for American
Standard Code for Information Interchange
char representation

char values are stored in 1 byte in memory, and


value range from -128 to 127 or 0 to 255
• Array?
• In simple terms: Collection of similar items is called an array
String – sequence of
characters(SURBALI) Final ice cream

[
[ humans[]
• char – to represent one character.
• yes – collection of y, e, s
• String isStrings
a sequence of characters
terminated(end) with a null
character \0
• Ex: char yes[]=“yes” y e s \0

• Compiler appends null(NUL) 0 1 2 3


character \0 at the end
• Two ways to declare a string in c
• String Literal
• Char array
Declaring string
• char name[]=“suresh”; //assigns memory automatically(string literal)

• char name[10]=“suresh”;
String literal //we have assigned 10 bytes of memory
• char name[]={‘s’,’u’,’r’,’e’,’s’,’h’,’\0’}; //declaring using char array

• What happens if you put more than 10 bytes🤔🤔


Char array
• It may do anything it wants: It may scold you, it say “taggede le” or it
can ask you to like this video. Literally anything…

NOTE: Will discuss more about strings later on


int a;
type = int
• It is used to store data size = 2 or 4 bytes
• It’s value can be changed at Range = -2,14,74,83,648 to 2,14,74,83,647
any time
Variable -
• Every variable in c has a
actual definition
specific type, which
determines the size of the
memory and the range of
values that can be stored
within that memory.
User defined type declaration
Declaration of variables – will be discussed later

• Primary type declaration


• data-type v;
• data-type v1,v2,….vn;
• Ex:
• int sum;
• int total, allCount;
• float percentage;
Basic data types: Modifiers:
int, char, float, double signed - To represent signed values( + and -)
Further classification – From
unsigned basic
- To represent only positive values( + )

data types
After introducing modifiers:
long
• int - affects the range of values(long, short)
short
• signed int
• unsigned int
• long int
• short int
• int –(32 bit environment) - 4 bytes – 32 bits
• Range: 2^32 => 4,29,49,67,296
• Signed: (positive and negative)=>
Signed and unsigned – int -2,147,483,647 to 2,147,483,647
• Unsigned: (only positive)=> 0 to 4,29,49,67,296

Default is signed
All basic data types with modifiers

19 decimal places
• You have to store half glass of water in one of the containers and you
can’t use the container for another purpose

Choose the best one


void: Special type known as empty data type that
Primary data types is used to state that a given variable does not have
any type. This is mainly used in defining functions
where we do not want to return any value.
void
char
double union Data types
int float enum
functions typedef Primary Secondary
structure Data types Data types
array pointer
Alpha User
Numeric Derived
numeric defined

Integer Decimal Character


int float char
double
void is not used for declaring
variables

• void noOfBores = 10;


void • void marks = 200;
• Above are invalid declarations

void is used with functions


It is used if nothing is passed in the function or
the function doesn't return anything.
RAM (4gb, 8gb, 16gb,
32gb)

Compiler
printfprograms.exe printfprograms.c HARD DISK (500gb,1tb,2tb)
/printfprograms.out
int a;
type = int
• It is used to store data size = 2 or 4 bytes
• It’s value can be changed at Range = -2,14,74,83,648 to 2,14,74,83,647
any time
Rules to define
Variable - variables
actual
definition
• Every variable in c has a
specific type, which
determines the size of the
memory and the range of
values that can be stored
within that memory.
• Who is the father of C Language?
• Dennis Ritchie
• dennis Ritchie
Case sensitive
• Dennis ritchie

• C language is case sensitive


1. Variable names may consists of letters, digits, and the underscore( _ )
characters

Rules to define variables


2. They must begin with either letter or underscore

Rules to define variables


3. White space is not allowed, instead use _ or camelCase
• Ex: total_sum, totalSum

Is there any mistake here?


4. Variable names case sensitive – Uppercase and lowercase are
significant.

Rules to define variables


5. Variable name should not be a keyword

Rules to define variables


• ANSI standard recognizes a length of 31 characters for a variable
name. However, the length should not be normally more than any
combination of eight alphabets, digits, and underscores.
Note – happens only in few
compilers
Valid or Invalid? Invalid
Valid or Invalid? Invalid
Valid
Valid or Invalid?
Storage classes

• Variables in C can have not only data type but also storage class that
provides information about their location and visibility

• Will discuss later


All Primary Data Types Secondary
Data types

User Derived
Defined Data types

Structure
Array

Union String

Typedef Pointer

Enum Functions

You might also like