Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tejalal Choudhary “Computer Programming” Fundamentals of “C”

Similar presentations


Presentation on theme: "Tejalal Choudhary “Computer Programming” Fundamentals of “C”"— Presentation transcript:

1 Tejalal Choudhary “Computer Programming” Fundamentals of “C”
Store Data Operate on Data Perform I/O Control the sequence “Computer Programming” Fundamentals of “C” VARIABLES, CONSTANTS & DATA TYPES Tejalal Choudhary Department of Computer Science & Engg SDBCT, Indore

2 Contents Need of variable, constant and data types Character set
Constants Variables Data types

3 What is C ? Programming Language Simple and easy to use
Many other languages are based on C Developed at AT & T’s Bell Laboratories of USA in 1972. Major parts of OS like Windows, UNIX, Linux is still written in C. Device driver are written in C Many mobile devices, consumer devices are based on C Popular gaming frameworks have been built using C Closely interact with the hardware devices. and so on…..

4 Analogy b/w English & C Steps in learning English language:
Steps in learning Programming language: Alphabets Words Sentences Paragraphs Alphabets, Digits, Special Symbols Constants, Variables, Keywords Instructions Program

5 Identifier Any user defined name Can be a name of
Variable, array, structure, Union ,Function etc. Should follow the naming rules of a language Naming Rules The first character in the variable name must be an alphabet or underscore. No commas or blanks are allowed within identifier No special symbol other than an underscore

6 Constants An entity that doesn’t change Types Integer (10, 20)
Real (10.56) Character (‘a’, ‘A’)

7 Variables Variable is an entity that may change.
It’s a Named memory location Each variable has some address Store constant value If not initialized constrains garbage value Can store one value at a time i.e. x=10 x=20 X –> Variable 10, 20 –> constant

8 Variable A B

9 Data-type variable-name;
Data Types Define Type for variable Range(max and min value it can store) Size(space required to store value) Data Type char short int long float double General Syntax for Variable Declaration Data-type variable-name; Char ch;

10

11 Byte Binary digit -> bit(0 or 1) One byte 0/1
One Byte can represent 28 =256 distinct values 0/1

12 Char(1 Byte) Char ch=‘A’; //65 64 +1 26+20
1 26 20

13 Short(2 Byte) Short s=519; =519

14 Short(2 Byte) +1 20 +…….+ 214 512+ 1024+ 2048+ 4096+ 8192+ 16384= 32767 + 1

15 Negative Numbers (Stored in 2’s complement)
Binary of is same as 32768 When we try to store it becomes Binary of = 1’s Complement of Binary of is : 1’s complement +1 2’s complement Binary of

16 Assigning one type to another
Char ch=‘A’; //65 Short s=ch; 65

17 Assigning one type to another
Short s=300; = Char ch=s; = 44

18 Lab Assignment 2 WAP which accepts a lower case character from the user and display the corresponding upper case character.(Hint: use <string.h> header file and its functions) Take length & breadth of rectangle from user. WAP to calculate area of rectangle.


Download ppt "Tejalal Choudhary “Computer Programming” Fundamentals of “C”"

Similar presentations


Ads by Google