ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
typedef struct error{int warning, error, exception;}error;

           main()

          {

              error g1;

              g1.error =1; 

              printf("%d",g1.error);

           }
 Question Submitted By :: Susie
I also faced this Question!!     Rank Answer Posted By  
 
  Re: typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }
Answer
# 1
Answer : 

		1

Explanation

      The three usages of name errors can be distinguishable
by the compiler at any instance, so valid (they are in
different namespaces).

      Typedef struct error{int warning, error, exception;}error;

This error can be used only by preceding the error by struct
kayword as in:

      struct error someError;

      typedef struct error{int warning, error, exception;}error;

This can be used only after . (dot) or -> (arrow) operator
preceded by the variable name as in :

      g1.error =1; 

              	printf("%d",g1.error);

  		typedef struct error{int warning, error, exception;}error;

This can be used to define variables without using the
preceding struct keyword as in:

      error g1;

Since the compiler can perfectly distinguish between these
three usages, it is perfectly legal and valid.

Note

      This code is given here to just explain the concept
behind. In real programming don’t use such overloading of
names. It reduces the readability of the code. Possible
doesn’t mean that we should use it!
 
Is This Answer Correct ?    1 Yes 0 No
Susie
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { int i=10; i=!i>14; Printf ("i=%d",i); }  1
String copy logic in one line. NetApp9
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }  1
print a semicolon using Cprogram without using a semicolon any where in the C code in ur program!! Tata-Elxsi19
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above HCL1
main() { int i = 3; for (;i++=0;) printf(“%d”,i); }  1
main() { int i=10; void pascal f(int,int,int); f(i++,i++,i++); printf(" %d",i); } void pascal f(integer :i,integer:j,integer :k) { write(i,j,k); }  1
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }  1
Finding a number which was log of base 2 NetApp1
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }  1
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }  1
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];  1
main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5 HCL1
main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }  1
#define max 5 #define int arr1[max] main() { typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; printf("%d %s",list[0],name); }  1
There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }  1
main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error HCL1
How to return multiple values from a function?  4
main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }  1
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com