GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  HCL  >  C
Next Question 
 C  |  Question 1 of 2    Print  
HCL - 35 C Interview Questions.

These are the questions usually repeated for C written Test.  You can alos use these questions to brushup your skills.

Instructions:
1.      Please ignore any case-sensitive errors and un-included libraries.
2.      You may use the back of this question paper for any rough work.

Q1.
main()
{
 int i;
 clrscr();
 printf("%d", &i)+1;
 scanf("%d", i)-1;
}
a. Runtime error.
b. Runtime error.  Access violation.
c. Compile error.  Illegal syntax
d. None of the above
 
 
 Ans: d, printf( ) prints address/garbage of i,
  scanf() dont hav & sign, so scans address for i
  +1, -1 dont hav any effect on code
Q2.
main(int argc, char *argv[])
{
       (main && argc) ? main(argc-1, NULL) : return 0;
}
a. Runtime error.
b. Compile error.  Illegal syntax
c. Gets into Infinite loop
d. None of the above
 
Ans: b)  illegal syntax for using return
Q3.
main()
{
  int i;
  float *pf;
  pf = (float *)&i;
 *pf = 100.00;
  printf("n %d", i);
}
a. Runtime error.
b. 100
c. Some Integer not 100
d. None of the above
 

Ans: d) 0
Q4.
main()
{
  int i = 0xff ;
  printf("n%d", i<<2);
}
a. 4
b. 512
c. 1020
d. 1024
 

Ans: c) 1020

Q5.
 #define SQR(x) x * x
main()
{
  printf("%d", 225/SQR(15));
}
a. 1
b. 225
c. 15
d. none of the above
 
Ans: b) 225
Q6.
union u
{
  struct st
 {
       int i : 4;
       int j : 4;
       int k : 4;
       int l;
 }st;
 int i;
}u;
main()
{
    u.i = 100;
    printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}
a. 4, 4, 0
b. 0, 0, 0
c. 100, 4, 0
d. 40, 4, 0
 

Ans: c) 100, 4, 0
Q7.
union u
{
     union u
    {
        int i;
        int j;
    }a[10];
    int b[10];
}u;
main()
{
      printf("n%d", sizeof(u));
      printf("  %d", sizeof(u.a));
//      printf("%d", sizeof(u.a[4].i));
}
a. 4, 4, 4
b. 40, 4, 4
c. 1, 100, 1
d. 40 400 4

Ans: 20, 200, error for 3rd printf
Q8.
main()
{
      int (*functable[2])(char *format, ...) ={printf, scanf};
      int i = 100;
      (*functable[0])("%d", i);
      (*functable[1])("%d", i);
      (*functable[1])("%d", i);
      (*functable[0])("%d", &i);
}
a. 100, Runtime error.
b. 100, Random number, Random number, Random number.
c. Compile error
d. 100, Random number
 
Q9.
main()
{
  int i, j, *p;
   i = 25;
   j = 100;
   p = &i; // Address of i is assigned to pointer p
  printf("%f", i/(*p) ); // i is divided by pointer p
}
a. Runtime error.
b. 1.00000
c. Compile error
d. 0.00000
 

Ans: c) Error becoz i/(*p) is 25/25 i.e 1 which is int & printed as a float,
 So abnormal program termination,
 runs if (float) i/(*p)   -----> Type Casting
Q10.
main()
{
       int i, j;
       scanf("%d %d"+scanf("%d %d", &i, &j));
       printf("%d %d", i, j);
}
a. Runtime error.
b. 0, 0
c. Compile error
d. the first two values entered by the user
 

Ans: d) two values entered, 3rd will be null pointer assignment
Q11.
main()
{
        char *p = "hello world";
        p[0] = 'H';
        printf("%s", p);
}
a. Runtime error.
b. “Hello world”
c. Compile error
d. “hello world”
 

Ans: b) Hello world
Q12.
main()
{
   char * strA;
   char * strB = I am OK;
   memcpy( strA, strB, 6);
}
a. Runtime error.
b. I am OK
c. Compile error
d. I am O
 
Ans: c)  I am OK is not in    "   "

Q13. How will you print % character?
a. printf(“%”)
b. printf(“\%”)
c. printf(“%%”)
d. printf(“%%”)

Ans: c) printf(" %% ");
Q14.
const int perplexed = 2;
#define perplexed 3
main()
{
    #ifdef perplexed
    #undef perplexed
    #define perplexed 4
    #endif
   printf("%d",perplexed);
}
a. 0
b. 2
c. 4
d. none of the above
 
Ans: c)
Q15.
struct Foo
{
  char *pName;
};
main()
{
    struct Foo *obj = malloc(sizeof(struct Foo));
    clrscr();
    strcpy(obj->pName,"Your Name");
    printf("%s", obj->pName);
}
a. Your Name
b. compile error
c. Name
d. Runtime error
 

Ans a)
Q16.
struct Foo
{
  char *pName;
  char *pAddress;
};
main()
{
    struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
    obj->pName = malloc(100);
    obj->pAddress = malloc(100);
    strcpy(obj->pName,"Your Name");
    strcpy(obj->pAddress, "Your Address");
    free(obj);
    printf("%s", obj->pName);
    printf("%s", obj->pAddress);
}
a. Your Name, Your Address
b. Your Address, Your Address
c. Your Name Your Name
d. None of the above
 
 

Ans: d) printd Nothing, as after free(obj), no memory is there containing
 obj->pName   &   pbj->pAddress
Q17.
main()
{
      char *a = "Hello ";
      char *b = "World";
clrscr();
      printf("%s", strcat(a,b));
}
a. Hello
b. Hello World
c. HelloWorld
d. None of the above
 

Ans: b)
Q18.
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
 
 
 
Ans: d) World, copies World on a, overwrites Hello in a.
Q19.
void func1(int (*a)[10])
{
       printf("Ok it works");
}
void func2(int a[][10])
{
   printf("Will this work?");
}
 
main()
{
   int a[10][10];
          func1(a);
   func2(a);
}
a. Ok it works
b. Will this work?
c. Ok it worksWill this work?
d. None of the above
 
 
 
Ans: c)
Q20.
main()
{
  printf("%d, %d", sizeof('c'), sizeof(100));
}
a. 2, 2
b. 2, 100
c. 4, 100
d. 4, 4
 
 
Ans: a) 2, 2
Q21.
main()
{
  int i = 100;
  clrscr();
  printf("%d", sizeof(sizeof(i)));
}
a. 2
b. 100
c. 4
d. none of the above
 

Ans: a) 2
Q22.
main()
{
  int c = 5;
  printf("%d", main||c);
}
a. 1
b. 5
c. 0
d. none of the above
 
Ans: a) 1,    if  we use main|c  then error, illegal use of pointer

Q23.
main()
{
   char c;
   int i = 456;
   clrscr();
   c = i;
   printf("%d", c);
}
a. 456
b. -456
c. random number
d. none of the above
 
 
 
Ans: d) -56
Q24.
void main ()
{
    int x = 10;
    printf ("x = %d, y = %d", x,--x++);
}
a. 10, 10
b. 10, 9
c. 10, 11
d. none of the above
 
 

Ans: d) Lvalue required
Q25.
main()
{
   int i =10, j = 20;
   clrscr();
   printf("%d, %d, ", j-- , --i);
   printf("%d, %d ", j++ , ++i);
}
a. 20, 10, 20, 10
b. 20, 9, 20, 10
c. 20, 9, 19, 10
d. 19, 9, 20, 10
 
 
 
Ans: c)
Q26.
main()
{
  int x=5;
  clrscr();
  for(;x==0;x--) {
    printf("x=%dn”", x--);
  }
}
a. 4, 3, 2, 1, 0
b. 1, 2, 3, 4, 5
c. 0, 1, 2, 3, 4
d. none of the above
 
 
Ans: d) prints nothing, as condition x==0 is False
Q27
main()
{
  int x=5;
  for(;x!=0;x--) {
    printf("x=%dn", x--);
  }
}
a. 5, 4, 3, 2,1
b. 4, 3, 2, 1, 0
c. 5, 3, 1
d. none of the above
 
 
 
Ans: d) Infinite loop as x is decremented twice, it never be 0
 and loop is going on & on
 
Q28
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
 

Ans: prints nothing, as condition in loop is false.
Q29.
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
 
Ans: 256, 512,     becoz these r different blocks, so declaration allowed
Q30.
main()
{
   int i;
   clrscr();
   for(i=0;i<5;i++)
  {
       printf("%dn",  1L << i);
  }
}
a. 5, 4, 3, 2, 1
b. 0, 1, 2, 3, 4
c. 0, 1, 2, 4, 8
d. 1, 2, 4, 8, 16
 

Ans: d) L does't make any diff.
Q31.
main()
{
  signed int bit=512, i=5;
   for(;i;i--)
  {
       printf("%dn",  bit = (bit >>  (i - (i -1))));
  }
}
a. 512, 256, 128, 64, 32
b. 256, 128, 64, 32, 16
c. 128, 64, 32, 16, 8
d. 64, 32, 16, 8, 4
 
Ans: b)
Q32.
main()
{
  signed int bit=512, i=5;
   for(;i;i--)
  {
       printf("%dn",  bit >>  (i - (i -1)));
  }
}
a. 512, 256, 0, 0, 0
b. 256, 256, 0, 0, 0
c. 512, 512, 512, 512, 512
d. 256, 256, 256, 256, 256
 

Ans: d) bit's value is not changed
Q33.
main()
{
     if (!(1&&0))
    {
  printf("OK I am done.");
    }
    else
   {
 printf("OK I am gone.");
   }
}
a. OK I am done
b. OK I am gone
c. compile error
d. none of the above
 
 
Ans: a)
Q34
main()
{
   if ((1||0) && (0||1))
  {
  printf("OK I am done.");
    }
    else
   {
 printf("OK I am gone.");
   }
}
a. OK I am done
b. OK I am gone
c. compile error
d. none of the above
 
 
Ans: a)
Q35
main()
{
   signed int bit=512, mBit;
  {
 mBit = ~bit;
 bit = bit & ~bit ;
 printf("%d %d", bit, mBit);
   }
}
a. 0, 0
b. 0, 513
c. 512, 0
d. 0, -513
 
Ans: d)



  
Total Answers and Comments: 9 Last Update: May 07, 2009   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: kareemmyk
 
plz explain question 3 and 4 plzzzz

Above answer was rated as good by the following members:
ashok54
September 05, 2005 14:13:51   #1  
kunal        

RE: HCL - 35 C Interview Questions.
answer of question no 5 is wrong its answer should be 1 option A
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
October 09, 2005 08:52:08   #2  
suman        

RE: HCL - 35 C Interview Questions.

hi

answer of 5th question is 225 only

i.e option b

bcoz it is executed as

225/15 * 15

15 * 15

225


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 11, 2006 04:59:23   #3  
shayantan basu        

RE: HCL - 35 C Interview Questions.
very good ....u r right suman...its (B)
 
Is this answer useful? Yes | No
June 23, 2006 05:11:59   #4  
Neelam        

RE: HCL - 35 C Interview Questions.
plz explain the working of question no 35 .
 
Is this answer useful? Yes | No
October 13, 2006 08:22:04   #5  
nani        

RE: HCL - 5 C Interview Questions.
yes ans of 5 is 15*15
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
January 05, 2007 01:23:45   #6  
Kumar Anuj        

RE: HCL - 35 C Interview Questions.

The question No. 35 works as follows (Please see the comments attached with each line)

main()
{
signed int bit 512 mBit; //signed int will take max. value 512 (will be - 1000000000)
{
mBit ~bit; // ~ means the reverse of a given number. That will be 0111111111 512
bit bit & ~bit ; // the & operation between 1000000000 and 0111111111 will be equal

// to 0.
printf( d d bit mBit); // returns the latest value of bit and mBit.
}
}


 
Is this answer useful? Yes | No
January 14, 2007 23:01:54   #7  
charu goel        

RE: HCL - 35 C Interview Questions.

No the answer of 5th question is 1 ie. option A

main()
{
printf( d 225/SQR(15));
}

sqr x*x

ie. 225/sqr(15 * 15)


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 10, 2008 00:14:09   #8  
kareemmyk Member Since: May 2008   Contribution: 1    

RE: HCL - 35 C Interview Questions.
plz explain question 3 and 4 plzzzz
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 07, 2009 03:01:58   #9  
myogeshchavan97 Member Since: December 2008   Contribution: 28    

RE: HCL - 35 C Interview Questions.
Q4.
main()
{
int i 0xff ;
printf("n d" i<<2);
}
a. 4
b. 512
c. 1020
d. 1024
binary of 0xff is 1111111111
left shifting it 2 times we get 1111111100 whose decimal value is 1020 hence o/p.
Ans: c) 1020

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Related Categories
Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape