Constant is something whose value does not change throughout the program.
Integer constant is a number without decimal point and fractional part
There are three types of integers constant.
1) Decimal integer
- The decimal integer consists of a set of digits, 0 to 9 having optional – or + sign. And Also, No other characters are allowed like space, commas, and non-digit characters.
- Ex: 123, -321, 0, +78
2) Octal integer
- The octal integer consists of any combination of digits from the set 0 to 7. Moreover, Octal numbers are always preceded by 0.
- Ex: 037, 0, 0551
3) Hexadecimal integer
- A hexadecimal integer consists of any combination of digits from the set 0 to 9 and A to F alphabets. Moreover, It always starts with 0x or 0X. A represents 10, B represents 11… F represents 15.
- Ex: 0X2A, 0x95, 0xA47C.
- The number containing the fractional part called real number. Ex: 0.0083, -0.75, +247.0, -0.75.
- A real number may also express in exponential notation.
- Moreover, The general form is: mantissa e exponent, ex: 215.65 can written as 2.1565e2.
- In exponential form, e2 means multiply by 102.
Single character constant
- It contains single character enclosed within a pair of single quote mark.
- Ex: ‘5’, ‘A’, ‘;’, ‘ ‘
- A string constant a sequence of characters enclosed within a double inverted comma.
- The characters may be letter, number, special character, blank space, etc…
- Ex: “DIET”, “1988”, “?A.B,!”, “5+3”, etc…
- ‘A’ is the character but “A” is the string.
printf() and scanf() function with syntax
The stdio.h header file provides built-in functions for reading (scanf) data from input devices (keyboard) and writing (printf) formatted data to output devices (monitor).
- scanf() is a library function that reads data with the specified format from standard input (keyboard).
- Syntax: int scanf(const char *format, …)
- Example: scanf(“%d”, &i);
- Moreover, The first argument is the specification of format and other arguments are pointer variables to store data.
- Also, The function returns the total number of items successfully read.
- scanf() stops when it exhausts its format string or when some input fails to match the control specification.
- printf() is a library function that prints formatted data to standard output, generally monitor.
- Syntax: int printf(char * format, arg1, arg2, …)
- Example: printf(“Your marks are %d”, mark);
- Moreover, The string format consists of two types of items – characters that will print on the screen, and format commands that define how the other arguments to printf() are displayed.
- printf() returns the number of characters printed.