We know the how to declare variable. We saw some example in my previous post. Here we will discuss about how to declare different types of data.
Data Type | Variable Declaration | Initializing | Declaration & Initializing |
---|---|---|---|
int | int A; | A = 12345; | int A = 12345; |
long long | long long b; | b = 123456789; | long long b = 123456789; |
float | float c; | c = 45.123456; | float c = 45.123456; |
double | double D; | D = 33.123456789; | double D = 33.123456789; |
char | char ch; | ch = 'k'; | char ch = 'k'; |
Let's look into the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <stdio.h> int main() { // variable declaration int variable1; long long variable2; float variable3; double variable4; char variable5; // initializing variable1 = 5; variable2 = 123456; variable3 = 454.123456789; variable4 = 34.123456789; variable5 = 'A' ; // printing printf ( "%d\n" ,variable1); printf ( "%lld\n" ,variable2); printf ( "%f\n" ,variable3); printf ( "%lf\n" ,variable4); printf ( "%c\n" ,variable5); return 0; } |
NOTE
- or are format specifier.
- is used for creating newline. if you run the above program you will find each of those output in different line.
No comments:
Post a Comment