0% found this document useful (0 votes)
34 views

Hsslive XI Comp App 06 Introduction To Programming

Pre-processor directives are lines that start with # and direct the compiler before compilation. Header files contain declarations for functions, objects, types and are included using directives like #include <iostream>. The main() function is where program execution begins and ends, and where other functions are called from. Comments are lines that describe a program and are ignored by the compiler, and are added using // for single-line and /* */ for multi-line comments.

Uploaded by

Layan
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)
34 views

Hsslive XI Comp App 06 Introduction To Programming

Pre-processor directives are lines that start with # and direct the compiler before compilation. Header files contain declarations for functions, objects, types and are included using directives like #include <iostream>. The main() function is where program execution begins and ends, and where other functions are called from. Comments are lines that describe a program and are ignored by the compiler, and are added using // for single-line and /* */ for multi-line comments.

Uploaded by

Layan
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/ 7

6.

INTRODUCTION TO PROGRAMMING
1. What is Pre-processor directive?

Pre processor are the compiler directive statements which direct the compiler to
process the information provided before actual compilation starts. They are lines
starts with # include in the program but not the part of it.

2. What is the use of header files in C++ program?

Header files contain information about functions, objects or derived data types
and are available along with compiler. .

Eg. # include <iostream>

iostream give information about the object cin and cout.

3. What is the use of main() in C++ ?

The execution of C++ program begins at main () and ends within main (). All other
function used in the program are called from main ().

4. What are L value and R value of variable?

A variable is associated with two values, L-value, its address and R-value, its
content.

5. What is garbage value of a variable?

It is the unpredictable value assigned to a variable at the time of its declaration.

6. What is initialization and dynamic initialization of variables?

Supplying value to a variable at the time of its declaration is called variable


initialization.

Eg. int x=100;

If the variable initialized during the execution of the program is known as


dynamic initialization.

Eg. int i=p*n*r/100;

7. Why do const is known as access modifier?

The const key word is used in the variable declaration to make its access read
only, ie we can’t change its value

Eg. const float p=3.14;

So const is known as access modifier.

© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam


8. What is type modifier in C++?

Type modifiers are given in the variable declaration to alter the size , range and
precision of the variable. Important type modifiers are signed , unsigned, long and
short.

9. What are arithmetic assigned operators in C++?

arithmetic assigned operators are C++ short hands used to represent arithmetic
binary operations such as +, - ,* , /.

By this method

a=a+10 ; can be written as a+=10;

Eg. a-=10; , a*=10; a/=10;

10. What is increment and decrement operators in C++?

++ is the increment operator in C++ used to incrementing the content of an


integer value by one.

Eg. ++a; , a++;

-- is the increment operator in C++ used to decrementing the content of an


integer value by one.

Eg. --a; , a- -;

There are two forms of increment/decrement operators, prefix form and post fix
form.

Prefix form: Here the operator is placed before the operand

Eg. int a=10;

C=++a; or c=- -a;

So the incrementation /decrementation takes first and then the assignment takes
place(ie. Change and then use method)

Postfix form: Here the operator is placed after the operand

Eg. int a=10;

c=a++; or c=-a- -;

So the incrementation /decrementation done after the assignment takes place(ie.


Use and then change method).

© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam


11. What is mean by precedence of operators?

It is the order of operations will carried out in C++ when different operations are

used with operands.

1. ( ) Parenthesis
2. ++, --, size of Unary operator
3. *, /, %
4. +, -
5. =, <, > etc Relational operators
6. ==, !=
7. &&
8. !!
9. ? :
10. =, += etc arithmetic assignment operator
11. , comma

12. What are the type conversion methods in C++?

If different types of numeric data are involved in an operator conversion


techniques are applied (eg. 5/ 2.0). So the data type of one operand is
converted in to another and is called type conversion. There are two ways
a). Implicit type conversion(Type Promotion)
It is done by C++ compiler internally. In expression where different types of
operands involved, C++ convert the lower sized operand to higher sized
operand . So it is known as type promotion.
Eg. int a,c;
float b;
a=2;
b=5.2;
c=a+b; Here c is promoted to float and result will be 7.2.
b). Explicit Conversion ( Type casting)
Here the programmer explicitly cast a data to the desired type. Usually
it is done in variables in expressions.
13. What is the use of adding comments in a program? How can we
include different types of comments I a C++ program?
Comments are the lines of codes that are added in the program to describe
the program. They are ignored by the compiler. Comments make the program
more readable.
There are two types of comments,
a). Single line comments: In C++ // is used to write single line comments
b). Multiline comments : These are included within /* and */.

© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam


Previous Questions
1. What is the name files created to support C++ programs and kept in the
standard library (1)
2. In C++ which among the following is NOT a rule for a valid identifier ?

a)The first character must be a letter or underscor(_).

b)White space and special characters are not allowed.

c)Keywords can be used as an identifier.

d)Upper and lower case can be treated differently. (1)


3. Memory requirement of void data type in C++ is ................ byte(s). (1)

4. The arithmetic assignment operation Y/=10 is equivalent to ...................


a) Y=10 b) Y=Y+10 c) Y=Y/10 d) None of these. (1)
5.Which of the following is not a C++ statement?

a). x = x + 10; b). x + = 10; c). x + 10 = x; d). x = 10+ x; (1)

6. Which header file is responsible for cout and cin objects? (1)

7. C++ program execution starts and ends within ......... function (1)
7. How do the type modifiers effect the size and range of int and char data types ? (2)
8. Briefly explain any two expressions in C++. (2)

8. What is the output of the following C++ Statements (2)

x=-7 ,y=3

a)add –x with –y

b)x modulus y
9. If a = 5, b = 7 and c = 3, predict the output of the following expressions . (2)
a) a
b) b% a
c) (a>c) && (a<b)
d) a/c
10.Predict the value of ‘b’ in the following C++ code after execution of each code
snippet.

a) and b) Justify your answer.

a) a=5 ; b= a++ ;
b) a=5 ; b=++a ; (2)

11. Explain the different types of programming errors . (2)


12. Comments in a program are ignored by the compiler. Then why should we
include comments?

© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam


Write the methods of writing comments in C++ Program. (2)
13. Write output of the following program?

# include <iostream>
using namespace std;
int main ()
{
Int a = 10 ;
cout<<”\n a= “ << a--;
cout<<”\n a= “ << --a;
return 0;

} (2)

14. The following program finds the sum of three numbers. Modify the program
to find the average. (Average should display fractional part also).
#include<iostream>
using namespace std;
int main ( )
{
int x ,y , z, result;
cout<<"Enter values f or x ,y, z" ;
cin>>x>>y>z;
result=x+y+z;
cout<<"The answer is ="<<result;
return 0;
} (2)
15. Write sample statements in C++ for the cascading of input and output
operators. (2)

16. Write a C++ program to print the following message.

( Hint : use only one cout statement).

“ SMOKING IS INJURIOUS TO HEALTH”

“ SAY GOODBYE TO DRUGS” (2)

17. Detect and correct the errors in the following C++ code.
#include<iostream>
using namespace std;
int main ( )
{
int a, b;
cout<<” Enter two numbers: “;
cin>>a and b;
a + b = c;
cout<<"Sum = “<<c;
return 0;
} (2)

© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam


18.In the following program,some lines are missing.Fill the missing lines and
complete it.

#include<iostream.h>
...............................................

Int num1,num2,sum;

cout<<”Enter two numbers:”;

..................................................................

..................................................................

Cout<<”Sum of numbers are =”<<sum;

} (3)

19. a). Consider the structure of C++ program given below and answer the
following question.

#include<iostream>

using namespace std;

int main( )

Statements;

Write the preprocessor directive statement in the code? (1)

b). Explain the header files in a program. (2)

20. Explain implicit and explicit type conversion with suitable examples. (3)

21. What are data types? Explain the fundamental data types in C++. (3)

22. What is the role of comments in a program? Explain the different ways to write
comments in a C++ program. (3)

23.What is implicit type conversion? Why it is called type promotion? (3)

24. Write a C++ program to check whether the given number is Prime or Not . (5)

25. Write a C++ program to find the total and percentage of a student in Six Subjects.(5)
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam

You might also like