PF Assignment Shortquestions Answer
PF Assignment Shortquestions Answer
Fundamentals
Assignment
Name: SYED ZAKIR HUSSAIN
SHAH
ROLL NO: 2K21/SWEE/81
Answer: Yes, C++ can be called OOPS. The full form of OOPS is
an Object-Oriented Programming System, which means a
paradigm that provides an application of various concepts,
including data binding, polymorphism, inheritance, and
various others.
Q8:Define a namespace?
//single-line comment
/* block comment */
Example:
int Result;
char c;
int a,b,c;
All the above are valid declarations. Also, note that as a result
of the declaration, the value of the variable is undetermined.
Result = 10;
C = ‘A’;
Example:
#include <iostream.h>
int main()
…..
Example:
#include <iostream.h>
int globalVar = 2;
int main()
int globalVar = 5;
cout<<globalVar<<endl;
Q18: When there are a Global variable and Local variable with
the same name, how will you access the global variable?
Answer: When there are two variables with the same name but
different scope, i.e. one is a local variable and the other is a
global variable, the compiler will give preference to a local
variable.
In order to access the global variable, we make use of a “scope
resolution operator (::)”. Using this operator, we can access the
value of the global variable.
Example:
#include<iostream.h>
int x= 10;
int main()
int x= 2;
Output:
Global Variable x = 10
local Variable x= 2
Constants
Apart from the decimal, C++ also supports two more constants
i.e. octal (to the base 8) and hexadecimal (to the base 16)
constants.
Examples of Constants:
75 //integer (decimal)
0113 //octal
0x4b //hexadecimal
3.142 //floating point
Example:
#include<iostream.h>
#define PI 3.142
int main ()
a = 5;
Example:
a = 2 + (b = 5);
is equivalent to:
b = 5;
a = 2 + b;
a = b = c = 5;
+ addition
– subtraction
* multiplication
/ division
% module
Example:
#include <iostream.h>
int main ()
cout<<”a + b = “<<a+b;
cout<”\na – b =”<<a-b;
cout<<”\na * b =”<<a*b;
cout<<”\na / b =”<<a/b;
cout<<”\na % b =“<<a%b;
return 0;
Output:
a+b=8
a – b =2
a * b =15
a / b =2
a % b=1
Example:
Example:
a=5;
a++;
a = a+1; or
a += 1;
a++;
Example:
a = 5; b=6;
++a; #a=6
b–; #b=6
–a; #a=5
b++; #6
Answer: In the iostream.h library of C++, cin, and cout are the
two data streams that are used for input and output
respectively. Cout is normally directed to the screen and cin is
assigned to the keyboard.
int age;
cin>>age;
Example:
cout<<”Hello, World!”;
cout<<123;
While (expression)
{statements;}
Example:
#include <iostream.h>
int main()
int n;
cin>>n;
while(n>0)
cout<<” “<<n;
--n;
do {statement;} while(condition);
Example:
#include<iostream.h>
int main()
int n;
cin>>n;
do {
cout<<n<<”,”;
--n;
}while(n>0);
cout<<”do-while complete”;
In the above code, we can see that the statement inside the
loop is executed at least once as the loop condition is at the
end. These are the main differences between the while and do-
while.
In case of the while loop, we can directly exit the loop at the
beginning, if the condition is not met whereas in the do-while
loop we execute the loop statements at least once.
Example:
void myfunc()
Cout<<”Hello,This is my function!!”;
int main()
{
myfunc();
return 0;
Example:
a *=2;
b *=2;
c *=2;
int main()
{
int x = 1,y=3,z=4;
printFunc(x,y,z);
Output:
x=1
y=3
z=4
a *=2;
b *=2;
c *=2;
int main()
int x = 1,y=3,z=4;
printFunc(x,y,z);
Output:
x=2
y=6
z=8