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

C and C++ Interview Questions

3. What is the default scope of if statement?

Ans:

The default scope of the if statement is only the next statement. So, to execute more than one tatement they must be written in a pair of braces.

Ex - 1:  What is the output?
main()
{
            float me = 1.1;
            double you = 1.1;
            if(me==you)
printf("I love U");
else
                        printf("I hate U");
}

Answer:
I hate U

Explanation:

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value  represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb:
Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) . 

Ex - 2:  What is the output?
main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s   %s",p,p1);
}

Ans:
ibj!gsjfoet

Ex - 3:  What is the output?
main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}

Ans:
hai

Explanation:
\n  - newline
\b  - backspace
\r  - linefeed


SLogix Student Projects
bottom