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

Notes Computer Science Class 12

Uploaded by

faheedmasood8
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Notes Computer Science Class 12

Uploaded by

faheedmasood8
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1

Computer Science XII (Notes 2024 – By Faheed Masood Hashmi(IMCB Mughal)


Chapter No. 3: OBJECT ORIENTED PROGRAMMING IN C++
Q1. Define a header file.
Ans. Header File: A header file contains C language definitions and structures. It is declared
at the top of a program with extension .h (dot h) using #include directive.
Examples of Header Files: iostream.h, conio.h, stdio.h, math.h etc.
Q2. What is meant by preprocessor directive in C++?
Ans. Preprocessor Directive: A preprocessor directive is a statement which starts with
#(hashtag symbol) at the beginning of a program. It is an instruction for the compiler before the
compilation starts.
Examples of Preprocessor Directive in C++: #include, #define, #undef etc.

Q3. What are reserved words in C++?


Ans. Reserved Words: Reserved words are special words which have been reserved by C
language for a predefined/specific purpose. There are about 80 reserved words in C++.
Examples of Reserved Words in C/C++: int, for, if, while, do etc.
Q4. What is a statement terminator in C/C++?
Ans. Statement Terminator (Semicolon): A semicolon (;) appears at the end of each C/C++
language statement. This is also known as a statement terminator.
Q5. Explain Comments in C++. Also describe types of comments used in C/C++.
Ans. Comments: Comments are used to explain statements of the source code. Comments
are not executed by the compiler. Comments make the program source code readable.
There are two types of comments in C/C++:-
Types of Comments inC/C++: There are two types of comments in C/C++:-
1. Single Line Comments: Single line comments start with // (double forward slash) and
continue only in the same line.
Example of Single Line Comment:
#include<iostream>
using namespace std;
int main(void)
{
cout<<"IMCB Mughal"; //ye output k liay hay.
return(0);
}
2. Multiple Lines Comments (/*and*/): Multiple line comments can cover multiple lines. A
multiple line comment starts with /* and ends with */.
Example of Multiple Line Comment:
#include<iostream>
using namespace std;
int main(void)
{
cout<<"IMCB Mughal"; /*ye output k liay hay.
This above statement is for showing
the output on screen*/
return(0);
}
2
Computer Science XII (Notes 2024 – By Faheed Masood Hashmi(IMCB Mughal)
Q6. Differentiate between a constant and a variable with suitable example.
Ans.
Constant Variable
A constant is a fixed value which remains the A variable is a named memory location which
same during the execution of a program. hold the value which can change during the
execution of a program.
#define or const keywords are used to int, char, float etc. keywords are used to
declare constants in C/C++ declare variables in C/C++.
Example: Example:
#define pi 3.42 int n=10;
Or float x=2.5;
const int pi=3.42;

Q7. Describe the rules for naming a variable in C++.


Ans. Rules for Specifying Variable Names in C++: The following rules are used when a
variable name is given:
1. The first character of a variable must be underscore (_) or an alphabet.
Example of valid name: int num1=10;
Example of invalid variable name: int 1num=10;
2. Special symbols such as $,%,^,& etc. cannot be used as variable name.
Example of valid name: int num=10;
Example of invalid variable name: int num$=10;
3. Blank space of comma is not allowed e.g. int num 1=10 is invalid because of space
character inside the variable name.
4. Reserved words of C/C++ language cannot be used as variable names.

You might also like