PDF - CodeQuotient
PDF - CodeQuotient
TUTORIAL
Chapter
1. Variables and Identifiers
Topics
1.2 Variable
1.3 Constants
1.7 Identifiers
Variable
data_type var_name;
https://codequotient.com/tutorialpdf/5a1d944752795c1b16c0abe5 1/5
8/27/23, 6:25 PM PDF | CodeQuotient
Constants
Constants refer to fixed values that the program may not alter.
Constants can be of any of the basic data types. The way each
constant is represented depends upon its type. Constants are also
called literals.
1 #include <stdio.h> C
2
3 int main()
4 {
5 char c = 'A'; // character constant
6 int i = 50; // integer constant
7 double df = 3.5; // double constant
8
9 printf("c = %c\n", c);
10 printf("i = %d\n", i);
11 printf("df = %lf\n", df);
12
13 return 0;
14 }
15
1 C++
2 #include<iostream>
3 #include<cstdio>
4 using namespace std;
https://codequotient.com/tutorialpdf/5a1d944752795c1b16c0abe5 2/5
8/27/23, 6:25 PM PDF | CodeQuotient
5
6 int main()
7 {
8 char c = 'A'; // character constant
9 int i = 50; // integer constant
10 double df = 3.5; // double constant
11
12 cout<<"c = "<<c<<endl;
13 cout<<"i = "<<i<<endl;
14 cout<<"df = "<<df;
15 return 0;
16 }
17
int a = 070;
and then want to print the value of a in decimal it is not 70, it is the
decimal equivalent of 70 base 8 which is 56. Also following is a
syntax error,
int a = 078;
as you are writing an octal constant, but in octal only digits from 0 to
7 can be used, hence 8 is not a valid digit in octal number system.
1 #include <stdio.h> C
2 int main()
3 {
4 int a = 070;
5 printf("a = %d", a);
6
7 return 0;
8 }
1 C++
2 #include<iostream>
https://codequotient.com/tutorialpdf/5a1d944752795c1b16c0abe5 3/5
8/27/23, 6:25 PM PDF | CodeQuotient
3 #include<cstdio>
4 using namespace std;
5
6 int main()
7 {
8 int a = 070;
9 cout<<"a = "<<a;
10
11 return 0;
12 }
13
Identifiers
https://codequotient.com/tutorialpdf/5a1d944752795c1b16c0abe5 4/5
8/27/23, 6:25 PM PDF | CodeQuotient
https://codequotient.com/tutorialpdf/5a1d944752795c1b16c0abe5 5/5