Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.

Similar presentations


Presentation on theme: "Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information."— Presentation transcript:

1

2 Constants, Variables and Data types in C

3 The C character Set A character denotes any alphabet, digit or special symbol used to represent information. Alphabets A,B, ….,Y, Z a,b, …..,y, z Digits 0,1,2,3,4,5,6,7,8,9 Special Symbols ~ ‘ ! @ # % ^ & * ( ) _ - + = | \ { } [ ] : ; “ ‘,. ? /

4 Identifiers Identifiers are names given to various program elements, such as variables, functions and arrays A variable name is any combination of alphabets, digits or underscores The first character in the variable name must be an alphabet

5 Variable It is a data name which is used to store data and may change during program execution. It is opposite to constant. Variable name is a name given to memory cells location of a computer where data is stored. * Rules for varibales: First character should be letter or alphabet. Keywords are not allowed to use as a variable name. White space is not allowed. C is case sensitive i.e. UPPER and lower case are significant. Only underscore, special symbol is allowed between two characters. The length of indentifier may be upto 31 characters but only only the first 8 characters are significant by compiler.

6 Types of C Constants C constants can be divided into two major categories Primary Constants Secondary Constants C Constants Primary ConstantsSecondary constants Integer Constant Real Constant Character Constant Array, Pointer Structure, Union Enum

7 Integer Constants An integer constant must have at least one digit It must not have a decimal point It could be either positive or negative If no sign precedes an integer constant, it is assumed to be positive No commas or blanks are allowed within an integer constant 1990, 194, -394

8 Real Constants Real constants(RC) must have at least one digit It must have a decimal point It could be either positive or negative Default sign is positive No commas or blank are allowed within a RC 194.143, -416.41

9 Character Constants A character constant is either a single alphabet, a single digit or a single special symbol enclosed within single inverted commas The maximum length of a character constant can be 1 character Eg ‘a’, ‘1’, ‘5’, ‘=‘ (Valid) ‘asd’, ‘12’ (Invalid)

10 String Constants A String Constant consists of any number consecutive characters enclosed in double quotation marks Escape sequence can be embedded within the string.

11 Keywords Keywords are the words whose meaning has already been explained to the C compiler They cannot be used as variable names. There are only 32 keywords available in c autodoubleifstaticdo breakelseintstructgoto caseenumlongswitchsigned charexternneartypedefwhile constfloatregisteruniondefault continuefarreturnunsignedfor shortvoid

12 C Instructions There are basically four types of instructions in C Type declaration instruction Eg int sum; float ave; char name,code; Input/Output instruction Eg scanf(), printf() Arithmetic Instruction Control instruction

13 Data Types C Supports several different types of data, each of which may be represented differently within the computers memory. Basic data types are listed below: Data Type Description Typical Memory int integer quantity 2 bytes char single character 1 bytes float floating point number 4 bytes double double-precision 8 bytes floating point number

14 Escape Sequences in C Certain non printing characters can be expressed in terms of escape sequences Character Escape Sequence ASCII Value bell \a 007 backspace \b 008 horizontal tab \t 009 vertical tab \v 001 newline \n 010 quotation mark (“) \” 034 question mark(?) \? 063 backslash (\) \\ 092 null \0 000

15 First C Program /* library function for input and output */ #include main() { int a,b,sum; /*variable declaration*/ printf(“enter the first number::\n”); scanf(“%d”,&a); /*receiving data from user */ printf(“enter the second no: \n “); scanf(“%d”,&b); sum =a+b; /* calculating the sum*/ printf(“the sum of two numbers: %d\n“,sum); }

16 Preparing and Running a Complete C Program. Planning a program Design the algorithm for the given program Statements must be selected and sequenced in the most effective manner Writing a C program Translate the algorithm into equivalent C instructions Comments should be included within a C program A well written program should generate clear, legible output. The program should be user interactive

17 Entering, Compiling and Executing The program can be entered into the computer using an EDITOR. (In Unix vi editor is used) Eg. vi filename.c Compiling and executing the program cc filename.c The object code a.out is generated The program can be executed by entering a.out in the prompt Program asks for required input and generates the output

18 Assignment 01 Q1 : Which of the following are invalid variable names and why ? interestpaid si-int AVERAGE Percent. 123 dist in km ot pay Name FLOAT

19 Question 1.explain various data types available in C? Question2. Explain the keywords and Constants in C ? What restrictions apply to their use?

20 Programming Assignment 01 Q2 : Point out the errors, if any, in the following C statements: int =314.562 *150 ; name = ‘Ajay’; 3.14 * r*r = area; k=a*b+c(2.5a+b); m_inst =rate of interest * numberofyears /100; area = 3.14 * r **2;

21 Assignment 01 Q3 : A C program contains the following statements: #include int i,j,k; write appropriate scanf and printf functions to enter and print the numerical values for i,j and k Q4 : Each new c instruction has to be written on a separate line. (True/false)


Download ppt "Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information."

Similar presentations


Ads by Google