Constant and Macros in C
In this tutorial, We will learn about constant and macros in C programming language.
In this tutorial, We will learn about constant and macros in C programming language.
Constant in C
In C program we use the const keyword to define a constant variable.
#include <stdio.h>
int main()
{
const int int_const_var = 10; // int constant
const float float_const_val = 4.14; // Real constant
const char char_const_val = 'A'; // char constant
printf("Integer constant :%d \n", intVal );
printf("Floating point constant : %f \n", floatVal );
printf("Character constant : %c \n", charVal );
return 0;
}
Macros in C
A Macro is typically an abbreviated name given to a piece of code or a value. In C program we achieve this with help of keyword #define #include<stdio.h>
#define int_var 10
#define float_var 4.5
#define char_var 'A'
int main()
{
printf("Integer Constant: %d\n", int_var);
printf("Floating point Constant: %f\n", float_var);
printf("Character Constant: %c\n", char_var);
return 0;
}
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment