© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

8.  Describe the main characteristics of static functions.
Ans:
            The main characteristics of static functions include,

  1. It is without the a this pointer,
  2. It can't directly access the non-static members of its class
  3. It can't be declared const, volatile or virtual.
It doesn't need to be invoked through an object of its class, although for convenience.             

Ex - 1: What is the subtle error in the following code segment?
           

main()
{
 void fun(int, int []);
   int n=5,arr[5];
   fun(n,arr);
}
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++<N)
                        p = &arr[i];
*p = 0;
}

Answer & Explanation:

If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program).

Ex - 2: What is the output?.

char *pointerFun()
            {
            char *temp = “pointer to the function";
            return temp;
            }
            int main()
            {
            puts(pointerFun());
            }

Ans:
pointer to the function

Explanation:

            The program suffers no problem and gives the output correctly because the character constants are stored in code/data area and not allocated in stack, so this doesn’t lead to dangling pointers.


SLogix Student Projects
bottom