PART A
1. What are pointers?
A pointer is a variable that holds a memory address. This address is the location
of another object in memory.
2. What are pointer operators?
The pointer operators are * and &.
The & is a unary operator that returns the memory address of its operand.
The * is a unary operator that returns the value located at the address that
follows.
3. What is meant by storage class specifiers?
Storage class specifiers tell the compiler how to store the subsequent variable.
There are five storage class specifiers supported by C++:
i. extern ii. static iii.register iv. auto v.mutable
4. What is the use of ‘extern’ variables?
In a multifile program, we can declare all of the global variables in
one file and use extern declarations in the other without defining it again.
The extern keyword has this general form:
extern var-list;
5. Write about union.
A union is a memory location that is shared by two or more different variables,
generally of different types , at different times. Declaring a union is similar to
declaring a structure. General form is:
union union-type-name{tmember-name; member-name;………} union-variables;
It allocates enough storage to hold the largest member of the union.
6. What is enumerated data type?
An enumerated data type is a user defined data type which provides a way of
attaching names to numbers.
Ex., enum shape{circle,square,rectangle};
enum color{red,blue,green};
Now the tag names shape and color become new type names .We can declare
new variables using them.
7. what is function?
Functions are the building blocks of C++ and the place where all program activity
occurs. The general form is
ret-type function-name(parameter list)
{body of the function }
The ret-type specifies the type of data that the function returns. The parameter
list
is a comma-separated list of variable names and their associated types that receive
the values of the arguments when the function is called. When the function is
called
the control is transferred to the first statement in the body.
5
8. What are the two ways to pass arguments to the function?
Call by value: This method copies the value of an argument into the formal
parameter of the function.
Call by reference: This method copies the address of an argument into the formal
parameter of the function.
9. How to create call by reference?
We can create call by reference by passing a pointer (i.e. address of the
argument ) to
an argument, instead of argument itself.
Example: void swap (int *x,int *y)
{int temp;
temp=*x;
*x=*y;
*y=temp;
}
this function can be invoked with the addresses of the arguments
as swap(&i,&j); //for interchanging the integer values i and j
10. What is function prototype?
In C++ all functions must be declared before they are used. This is normally
accomplished using function prototype. Using function prototype, the compiler can
find and report any illegal type conversions between the type of arguments used to
call a function and the type definition of its parameter.
General form is: ret-type function-name(type param-name1,type paramname2,……type
paramnamen);
11. What is the difference between endl and ‘\n'?
Using endl flushes the output buffer after sending a '\n', which means endl is more
expensive in performance. Obviously if you need to flush the buffer after sending a
'\n', then use endl; but if you don't need to flush the buffer, the code will run
faster if
you use '\n'.
12. What is the use of reference variables?
A reference variable provides an alias (alternate name) for a previously defined
variable. A reference variable is created as follows:
Datatype & reference-name =variablename;
Example: int i=10;
int &sum=i;
cout<<sum; // output:10
sum=100;
cout<<i; // outp