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

C and C++ Interview Questions

8. Diffrentiate between Structure and Array?
Ans:

In the C programming language, a structure may contain Multiple Data Types, also including arrays of those types, and the structure becomes a User-Defined type.
An array may contain a number of items all of the Same Type, including user-defined types such as structures .

Ex - 1:  What is the output?
enum colors {BLACK,BLUE,GREEN}
 main()

printf("%d..%d..%d",BLACK,BLUE,GREEN);  
return(1);
}
Ans:
0..1..2

Ex - 2:  What is the output?
enum assigns numbers starting from 0, if not explicitly defined.
 #include<stdio.h>
main()
{
  struct xx
   {
      int x=3;
      char name[]="hello";
   };
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}
Ans:
Compiler Error
Explanation:

Initialization should not be done for structure members inside the structure declaration

Ex - 3:  What is the output?
#include<stdio.h>
main()
{
struct xx
 {
        int x;
        struct yy
         {
           char s;
           struct xx *p;
         };
                   struct yy *q;
            };
            }
Ans: Compiler Error
Explanation:

In the end of nested structure yy a member have to be declared.


SLogix Student Projects
bottom