Discover the depth  of  C

  C C++  Linux ProgrammingNEW   Operating Systems  Data StructuresNEW  Compilers  Contact Us

Navigation

?? Interview Questions ??New

Join C4Swimmers

 sitepromotion.gif (577 bytes) New Member

Weekly Queries New

 Queries for this week

 All Weekly Queries

Code Zone - Free

Newbie Level

Intermediate Level

Tools Zone

C/C++ Tools

Test Your C/C++ Skills

  Playing with printf

  Playing with scanf

  Branching & Loops

  Pointers Part I

  Pointers Part II

  Structure & Union

C Special

  Discovering C
  IFAQs

  Self-reproducing C Code

  C/C++ Links
  C/C++ Books NEW

Programming Problems

  Part I
  Part II
Downloads
C4S - Solution Pack
Data Structures
C++ & 8086 ALP
ADA & System S/w
Online Certifications
premiumservices.gif (1070 bytes) Brainbench
premiumservices.gif (1070 bytes) Benchmarks Global
Help and Support
customer_care_small.gif (1018 bytes)  Suggestions
post-question_icon.gif (1062 bytes)  Contribute
premiumservices.gif (1070 bytes)  Advertise with us
memberhome.gif (1052 bytes)  -Home Page-

premiumservices.gif (1070 bytes) Feedback

As a webmaster of this site, I regard you as our most important critic and commentator. We value your opinion and want to know what we are doing right, what we could do better and any other words of wisdom you're willing to pass our way. It would be our greatest motivation which will help us in developing areas you would like to see in this site. We hope you will continue to encourage and support us in our future endeavors.

 
.  

C For Swimmers : Mastering C step-by-step

Google


WWW c4swimmers.esmartguy.com
NOTE : It is assumed that -

Necessary header files are included
Programs/Snippets are tested under Linux as well as Windows platform
Programs/Snippets are compiled using VC++ 6.0 as well as gcc 3.2
The underlying machine is an x86 system

Structures & Unions

 [Q001] What will be the output of the following program :
 struct {
              int i;
              float f;
           }var;
 int main()
 {
    var.i=5;
    var.f=9.76723;
    printf("%d %.2f",var.i,var.f);
    return(0);
 }
 (a)Compile-Time Error
 (b)5 9.76723
 (c)5 9.76
 (d)5 9.77
 [Q002] What will be the output of the following program :
 struct {
              int i;
              float f;
           };
 int main()
 {
    int i=5;
    float f=9.76723;
    printf("%d %.2f",i,f);
    return(0);
 }
 (a)Compile-Time Error
 (b)5 9.76723
 (c)5 9.76
 (d)5 9.77
 [Q003] What will be the output of the following program :
 struct values {
                         int i;
                         float f;
                      };
 int main()
 {
    struct values var={555,67.05501};
    printf("%2d %.2f",var.i,var.f);
    return(0);
 }
 (a)Compile-Time Error
 (b)55 67.05
 (c)555 67.06
 (d)555 67.05
 [Q004] What will be the output of the following program :
 typedef struct {
                           int i;
                           float f;
                       }values;
 int main()
 {
    static values var={555,67.05501};
    printf("%2d %.2f",var.i,var.f);
    return(0);
 }
 (a)Compile-Time Error
 (b)55 67.05
 (c)555 67.06
 (d)555 67.05
 [Q005] What will be the output of the following program :
 struct my_struct {
                              int i=7;
                              float f=999.99;
                           }var;
 int main()
 {
    var.i=5;
    printf("%d %.2f",var.i,var.f);
    return(0);
 }
 (a)Compile-Time Error
 (b)7 999.99
 (c)5 999.99
 (d)None of these
 [Q006] What will be the output of the following program :
 struct first {
                     int a;
                     float b;
                 }s1={32760,12345.12345};
 typedef struct {
                           char a;
                           int b;
                       }second;
 struct my_struct {
                              float a;
                              unsigned int b;
                           };
 typedef struct my_struct third;
 int main()
 {
     static second s2={'A',- -4};
     third s3;
     s3.a=~(s1.a-32760);
     s3.b=-++s2.b;
     printf("%d %.2f\n%c %d\n%.2f %u",(s1.a)--,s1.b+0.005,s2.a+32,s2.b,++(s3.a),--s3.b);
    return(0);
 }
 (a)Compile-Time Error
 (b)32760 12345.12
     A 4
     1 -5
 (c)32760 12345.13
     a -5
     0.00 65531
 (d)32760 12345.13
     a 5
     0.00 65530
 [Q007] What will be the output of the following program :
 struct {
              int i,val[25];
           }var={1,2,3,4,5,6,7,8,9},*vptr=&var;
 int main()
 {
     printf("%d %d %d\n",var.i,vptr->i,(*vptr).i);
     printf("%d %d %d %d %d %d",var.val[4],*(var.val+4),vptr->val[4],*(vptr->val+4),(*vptr).val[4],*((*vptr).val+4));
    return(0);
 }
 (a)Compile-Time Error
 (b)1 1 1
     6 6 6 6 6 6
 (c)1 1 1
     5 5 5 5 5 5
 (d)None of these
 [Q008] What will be the output of the following program :
 typedef struct {
                           int i;
                           float f;
                       }temp;
 void alter(temp *ptr,int x,float y)
 {
     ptr->i=x;
     ptr->f=y;
 }
 int main()
 {
     temp a={111,777.007};
     printf("%d %.2f\n",a.i,a.f);
     alter(&a,222,666.006);
     printf("%d %.2f",a.i,a.f);
    return(0);
 }
 (a)Compile-Time error
 (b)111 777.007
     222 666.006
 (c)111 777.01
     222 666.01
 (d)None of these
 [Q009] What will be the output of the following program :
 typedef struct {
                           int i;
                           float f;
                       }temp;
 temp alter(temp tmp,int x,float y)
 {
     tmp.i=x;
     tmp.f=y;
     return tmp;
 }
 int main()
 {
     temp a={111,777.007};
     printf("%d %.3f\n",a.i,a.f);
     a=alter(a,222,666.006);
     printf("%d %.3f",a.i,a.f);
    return(0);
 }
 (a)Compile-Time error
 (b)111 777.007
     222 666.006
 (c)111 777.01
     222 666.01
 (d)None of these
 [Q010] What will be the output of the following program :
 typedef struct {
                           int i;
                           float f;
                       }temp;
 temp alter(temp *ptr,int x,float y)
 {
     temp tmp=*ptr;
     printf("%d %.2f\n",tmp.i,tmp.f);
     tmp.i=x;
     tmp.f=y;
     return tmp;
 }
 int main()
 {
     temp a={65535,777.777};
     a=alter(&a,-1,666.666);
     printf("%d %.2f",a.i,a.f);
    return(0);
 }
 (a)Compile-Time error
 (b)65535 777.777
     -1 666.666
 (c)65535 777.78
     -1 666.67
 (d)-1 777.78
     -1 666.67
 [Q011] What will be the output of the following program :
 struct my_struct1 {
                                int arr[2][2];
                            };
 typedef struct my_struct1 record;
 struct my_struct2 {
                                record temp;
                            }list[2]={1,2,3,4,5,6,7,8};
 int main()
 {
     int i,j,k;
     for (i=1; i>=0; i--)
          for (j=0; j<2; j++)
               for (k=1; k>=0; k--)
                    printf("%d",list[i].temp.arr[j][k]);
    return(0);
 }
 (a)Compile-Time Error
 (b)Run-Time Error
 (c)65872143
 (d)56781243
 [Q012] What will be the output of the following program :
 struct my_struct {
                               int i;
                               unsigned int j;
                          };
 int main()
 {
     struct my_struct temp1={-32769,-1},temp2;
     temp2=temp1;
     printf("%d %u",temp2.i,temp2.j);
    return(0);
 }
 (a)32767 -1
 (b)-32769 -1
 (c)-32769 65535
 (d)32767 65535
 [Q013] What will be the output of the following program :
 struct names {
                          char str[25];
                          struct names *next;
                      };
 typedef struct names slist;
 int main()
 {
     slist *list,*temp;
     list=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation
     strcpy(list->str,"Hai");
     list->next=NULL;
     temp=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation
     strcpy(temp->str,"Friends");
     temp->next=list;
     list=temp;
     while (temp != NULL)
     {
         printf("%s",temp->str);
         temp=temp->next;
     }
    return(0);
 }
 (a)Compile-Time Error
 (b)HaiFriends
 (c)FriendsHai
 (d)None of these
 [Q014] What will be the output of the following program :
 (i) struct A {
                      int a;
                      struct B {
                                       int b;
                                       struct B *next;
                                   }tempB;
                      struct A *next;
                  }tempA;

 (ii) struct B {
                      int b;
                      struct B *next;
                   };
     struct A {
                      int a;
                      struct B tempB;
                      struct A *next;
                  };
 
 (iii) struct B {
                       int b;
                    }tempB;
       struct {
                    int a;
                    struct B *nextB;
                };

 (iv) struct B {
                       int b;
                       struct B {
                                        int b;
                                        struct B *nextB;
                                    }tempB;
                       struct B *nextB;
                   }tempB;
 (a) (iv) Only
 (b) (iii) Only
 (c)All of the these
 (d)None of these
 [Q015] What will be the output of the following program :
 union A {
                  char ch;
                  int i;
                  float f;
              }tempA;
 int main()
 {
     tempA.ch='A';
     tempA.i=777;
     tempA.f=12345.12345;
     printf("%d",tempA.i);
    return(0);
 }
 (a)Compile-Time Error
 (b)12345
 (c)Erroneous output
 (d)777
 [Q016] What will be the output of the following program :
 struct A {
                  int i;
                  float f;
                  union B {
                                   char ch;
                                   int j;
                               }temp;
             }temp1;
 int main()
 {
     struct A temp2[5];
     printf("%d %d",sizeof temp1,sizeof(temp2));
    return(0);
 }
 (a)6 30
 (b)8 40
 (c)9 45
 (d)None of these
 [Q017] What will be the output of the following program :
 int main()
 {
     static struct my_struct {
                                            unsigned a:1;
                                            unsigned b:2;
                                            unsigned c:3;
                                            unsigned d:4;
                                            unsigned :6; // Fill out first word
                                       }v={1,2,7,12};
     printf("%d %d %d %d",v.a,v.b,v.c,v.d);
     printf("\nSize=%d bytes",sizeof v);
    return(0);
 }
 (a)Compile-Time Error
 (b)1 2 7 12
     Size=2 bytes
 (c)1 2 7 12
     Size=4 bytes
 (d)None of these
 [Q018] What are the largest values that can be assigned to each of the bit fields defined in [Q017] above.
 (a)a=0 b=2 c=3 d=4
 (b)a=1 b=2 c=7 d=15
 (c)a=1 b=3 c=7 d=15
 (d)None of these
 [Q019] What will be the output of the following program :
 int main()
 {
    struct sample {
                              unsigned a:1;
                              unsigned b:4;
                          }v={0,15};
    unsigned *vptr=&v.b;
    printf("%d %d",v.b,*vptr);
    return(0);
 }
 (a)Compile-Time Error
 (b)0 0
 (c)15 15
 (d)None of these
 [Q020] What will be the output of the following program :
 int main()
 {
     static struct my_struct {
                                            unsigned a:1;
                                            int i;
                                            unsigned b:4;
                                            unsigned c:10;
                                       }v={1,10000,15,555};
     printf("%d %d %d %d",v.i,v.a,v.b,v.c);
     printf("\nSize=%d bytes",sizeof v);
    return(0);
 }
 (a)Compile-Time Error
 (b)1 10000 15 555
     Size=4 bytes
 (c)10000 1 15 555
     Size=4 bytes
 (d)10000 1 15 555
     Size=5 bytes

Click here to see the Solutions for the above queries.

You are Visitor No.

Sign my Guestbook View my Guestbook

Subscribe to C4Swimmers Group
Designed and Maintained by  Nanda Kishor

Thanks for using C For Swimmers.
Regarding this material, you can send Bug Reports, Suggestions, Comments, etc. to

nandakishorkn@rediffmail.com

Note: All logos or trademarks are related to their respective owners.

Although every precaution has been taken, the designer(s) owe no responsibility for malicious errors.

No liability assumed for damages resulting from the use of the available information.