Presentation is loading. Please wait.

Presentation is loading. Please wait.

Wel come.

Similar presentations


Presentation on theme: "Wel come."— Presentation transcript:

1 wel come

2 BILASPUR UNIVRSITY,BILASPUR
Department Of Computer Science & Application Assignment- Constants In C Guided By: Presented By:- Mr. Jeetendra sir Ajay Thakur

3 CONSTANTS : 1. What is constant. 2. Declaring constants
3. Basic types of constant. 4. Integer constant. 5. Real constant. 6. Single character constant. 7. String constant. 8. Backslash character constant.

4 What is constant : Constants are data values that cannot be changed during the execution of a program. Like variables have a type. In this section, we discuss Boolean ,character , integer , real , complex , and string constants.

5 Declaring constants : Declaring a constants allows you to quickly and easily change a value that is used throughout your code simply by changing the declaration . Unlike variables , constants are declared using the c language preprocessor and not the compiler . Here’s the format : #define PI

6 Declaring constants : #include<stdio.h> #define PI 3.14
void main () { float R,area,square; R=2.5; area = 4*PI*R*R; square =4/3*PI*R*R*R; printf(“%f %f”,area,square); }

7 Single character constants
Types of constant : constants Numeric constants Integer constants Real constants Character constants Single character constants String constants

8 Integer constants : An integer constant refers to a sequence of digits. there three types of integers , namely ,decimal integer , octal integer and hexadecimal integer. decimal integer consist of a set of digit . valid example: an octal integer constant consists of any combination of digits from the set 0 through 7 with a leading 0. valid example: a sequence of digits preceded by 0x or 0X is considered as hexadecimal integer . Valid example: 0X2 0x9F 0Xbcd 0x

9 Integer constants : valid remarks 25,000 $255 0X7B No
Yes No Represents long integer Comma is not allowed $ symbol is not permitted Hexadecimal integer

10 Real constants : Integer numbers are inadequate to represent quantities that vary continuously , such as distances , heights ,temperatures , prices , and so on . Examples of real constants are: It is possible to omit digits before the decimal point , or digits after the decimal point . That is , A real number may also be expressed in exponential notation . For example , the value may be written as 2.156e2 in exponential notation . E2 means multiply by The general for is : Mantissa e exponent The mantissa is either a real number expressed in decimal notation or an integer . Example of legal floating-point constants are: e4 12e e E3 -1.2E-1

11 Real constants : Valid? Remarks Constant +5.0E3 3.5e-5 7.1e 4 1.5E+2.5
Yes No ANSI c support unary plus ----=----- No white space is permitted Exponent must be an integer

12 Single char. constants :
A single character constant contains a single character enclosed within a pair of single quote marks . Example of charater constants are: ‘5’ ‘X’ ‘;’ ‘ ’ Note that the character constant ‘5’ is not the same as the number 5. Character constant have integer values known as ASCII value . For example , the statement Printf(“%d”,’a’); Would print the number 97,the ASCII value of the letter a .

13 String Constants : A string constant is a sequence of characters enclosed in double quotes . The characters may be letters , number , special characters and blank space examples are : “Hello!” “1987” “well done” “?....!” “5+3” “X” Remember that a character constant is not equivalent to single character string constant . Further , a single character string constant does not have an equivalent integer value while a character constant has an integer value . Character string are often used in programs to build meaningful programs .

14 Backslash char Constants :
C supports some special backslash character constants that are used in output functions . For example , the symbol ‘\n’ stands for newline character. A list of such backslash character constant is given in table . Note that each one of them represents one character , although they consist of two characters .

15 Backslash char Constants :
Meaning ‘\n’ ‘\b’ ‘\f’ ‘\r’ ‘\t’ ‘\v’ ‘\’ ‘\”’ ‘\?’ ‘\\’ ‘\0’ Audible alert (bell) Back space Form feed New line Carriage return Horizontal tab Vertical tab Single quote Double quote Question mark Backslash null

16 Thank you


Download ppt "Wel come."

Similar presentations


Ads by Google