0% found this document useful (0 votes)
9 views3 pages

CEC-101 - P2 - Data Types and Variables

This document provides a practical exercise on data types and variables in C++. It contains 9 questions covering primitive and derived data types, variable declaration and initialization, output of code snippets, difference between variable types, valid variable names, character representation, and debugging programs with syntax errors.

Uploaded by

DHRUV SONI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

CEC-101 - P2 - Data Types and Variables

This document provides a practical exercise on data types and variables in C++. It contains 9 questions covering primitive and derived data types, variable declaration and initialization, output of code snippets, difference between variable types, valid variable names, character representation, and debugging programs with syntax errors.

Uploaded by

DHRUV SONI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CEC 101: Computer Programming

Civil Engineering Autumn 2023-24


Prac�cal 2: Data types and variables
1. Which type of data type is designed by the programmer?
a) primi�ve
b) derived
c) user-defined

2. Write output of following:


a) b)
#include <iostream> #include <iostream>
using namespace std; #include <string>
int main() using namespace std;
{ int main()
int a = 55; {
int b = 44; char a = ’55’;
cout<<a+b; char b = ’44’;
return 0; cout<<a+b;
} return 0;
}

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;
}

3. State difference between


int a = 10;
int a[10];

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

7. Run the following program and check the output:

#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;
}

You might also like