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

C and C++ Interview Questions

2.  Why should I prototype a function?

Ans:

A function prototype tells the compiler what kind of arguments a function is looking to receive and what kind of return value a function is going to give back. This approach helps the compiler ensure that calls to a function are made correctly and that no erroneous type conversions are taking place.

Ex - 1:  What are the following notations of defining functions known as?
i.      int abc(int a,float b)
                        {
                        /* some code */
 }

ii.    int abc(a,b)
        int a; float b;
                        {
                        /* some code*/
                        }

Ans:
i.  ANSI C notation
ii. Kernighan & Ritche notation

Ex - 2 what is the output?:

main(){
 char a[100];
 a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
 abc(a);
}
abc(char a[]){
 a++;
             printf("%c",*a);
 a++;
 printf("%c",*a);
}
Ans: bc

Explanation:
The base address is modified only in function and as a result a points to 'b' then after incrementing to 'c' so bc will be printed.


SLogix Student Projects
bottom