CEC-101 - P2 - Data Types and Variables
CEC-101 - P2 - Data Types and Variables
c) d)
#include <iostream> #include <iostream>
using namespace std; using namespace std;
int main() int main()
{ {
bool b = 5; char a = 75;
cout<<b; char b = '75';
return 0; cout<<a<<endl;
} cout<<b<<endl;
return 0;
}
4. Print ascii values of characters ‘X’ , ‘ ’ , ‘*’ , ‘a’ , ‘A’ , ‘.' , ‘;’ , ’b’.
5. Run the program in the compiler. Can you state the reason for the unexpected output?
#include <iostream>
using namespace std;
int main()
{
int a=100000*100000;
cout<<a;
return 0;
}
6. Following are the names of certain variables used by a programmer to code in C++. Iden�fy
the variables which are NOT valid in C++ and give reason:
a) first_name
b) firstName
c) first_name
d) _firstName
e) first2020Name
f) 1stName
g) first%name
h) %first_name
i) FirstName
j) First_name
#include <iostream>
using namespace std;
int main()
{
char A = 112; char B = '112';
cout << A << "\n"; cout << B;
return 0;
}
Is there any difference between the data stored in variables A and B? Why?
8. Declare variables to take the density (kg/m3), length (m), and cross-sec�onal area (m2) of a
steel beam as inputs and display its total weight as output.
9. Debug the following programs:
a)
#include <iostream>
using namespace std
int main()
{
int %marks = 72;
cout << "Your marks is" \n;
cout << %marks;
return 0;
}
b)
#include <iostream>
using namespace std;
int main()
{
int physics=74, chemistry=87, maths=92;
total = physics + chemistry + maths;
cout << total;
return 0;
}
c)
#include <iostream>
using namespace std;
int main()
{
const int length = 19456783;
const int breadth = 45309876;
long long int area = length *breadth;
cout << area;
return 0;
}