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

C and C++ Interview Questions

Ex - 8: What is the output?

main()
      {
      int k=1;
      printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
      }
Ans:
1==1 is TRUE
Explanation:

When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE".

Ex - 9:  What is the output?
main()
      {
      int y;
      scanf("%d",&y); // input given is 2000
      if( (y%4==0 && y%100 != 0) || y%100 == 0 )
           printf("%d is a leap year");
      else
           printf("%d is not a leap year");
      }
Ans:
2000 is a leap year.

Explanation:
An ordinary program to check if leap year or not.

Ex -10:  What is the output?
main()
{
      char s[ ]="man";
      int i;
      for(i=0;s[ i ];i++)
      printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Ans: mmmm
            aaaa
             nnnn
Explanation:

s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally  array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the  case of  C  it is same as s[i].


1 >> 2 >> 3 >> 4
SLogix Student Projects
bottom