Constant in C

Constant in C


As the name suggests the name constants is given to such variables or values in C/C++ programming language which cannot be modified once they are defined. They are fixed values in a program. There can be any types of constants like integer, float, char etc.

If you want to define a variable whose value cannot be changed, you can use the const keyword. This will create a constant. 

const double PI = 3.14;

Notice, we have added keyword const.

Here, PI is a symbolic constant; its value cannot be changed.

const double PI = 3.14;
PI = 2.9; //Error

List of Constants in C


Constant
Example
Decimal Constant
10, 20, 450 etc.
Real or Floating-point Constant
10.3, 20.2, 450.6 etc.
Octal Constant
021, 033, 046 etc.
Hexadecimal Constant
0x2a, 0x7b, 0xaa etc.
Character Constant
'a', 'b', 'x' etc.
String Constant
"c", "Infomax", "Infomax Academy" etc.



Programs

Write a program to input number of days from user and display it, week and days format.


For Example

input is : 20 days

then output is:

2 week and 6 days.



View Solution


Write a program to input number of days from user and display it, Month, Week and Days format. (consider 30days = 1 month)


For Example:

input is : 50 days


output is: 1 month, 2 week and 6 days.



View Solution


Write a C program which accept a character from user and ASCII Value of that character


View Solution


Write a program which accept one integer number from user and print it.


View Solution


Write a C Program to input any Character and Find its ASCII Value


View Solution


Write a C Program to input dividend, divisor and Compute Quotient and Remainder


View Solution


Write a C Program to Find the Size of int, float, double and char


View Solution


Write a C Program to Swap Two Numbers


View Solution


Write a C program to Swap Numbers Without Using Temporary(3rd) Variables


View Solution


Write a C Program to input any  number and Check  number is Odd or Even Using the Ternary Operator


View Solution