HCL Placement Paper Collection Part II

Section 2 – C Programming

1.which of the following about the following two declarations is true
i) int *F();
ii)int (*F)();
a)Both are identical b)the first is a correct declaration and second is wrong
c)the first declaration is a function returning a pointer to an integer and the second is a pointer to a function
returning int
d)Both are different ways of declaring pointer to a function (ans. (c))

2.what are the values printed by the following program?
#define dprintf(expr) printf("expr=%d\n”,expr)
main() {
int x=7;
int y=3;
dprintf(x/y); }
a)#2=2 b)expr=2 c)x/y=2 d)none (ans.( c))

3.which of the following is true of the following program
main() {
char *c;
int *ip;
c=(char *)malloc(100);
ip=(int *)c;
free(ip); }
a)the code functions properly by releasing all the memory allocated
b)results in compilation error as a pointer of various types cannot be equated
c)the program ties to free more memory than allocated and results in run time error
d) works well except when the machine runs low on memory and malloc is unabel to allocate the memory (ans. (d))

4.output?
main() {
int i;
char *p;
i=0x89;
p=(char *)i;
p++;
printf(“%x\n”p); }
a)0x8c b)0x4566788A c)0x8A d)0x8B e)none (ans. (c))

5.which of the following is not an ANSI C language keyword?
a)volatile b)function c)default d)const e)void (ans. (b))

6.when an array is passed as parameter to a function , which of the following statement is correct
the function can change values in the original array
in c parameters are passed by value the function cannot change the original value in the array
it results in compilation error.Array cannot be passed as a parameter to a function
results in runtime error when the function tries to access the elements in the array

7.the type of the controlling expression of a switch statement cannot be of the type
a)int b)char c)short d)float e)none (ans.(d))

8.value of (3^6)+(a ^a)=? (Ans. value=5)

9.x= b>8?b<<3:b>4?b>>1:b; (ans. x=3)

10.output:
main() {
int n=2;
printf(“%d %d\n”,++n,n*n); }
a)3,6 b)3,4 c)2,4 d)cannot determine (ans.( b))

11.output:
int x=0x65;
main() {
char x;
printf(“%d\n”,x); }
a) Compilation error b)’A’ c)65 d)undefined

12.output
main() {
int a=10;
int b=6;
if(a=3)
b++;
printf(“%d %d”,a,b++); }
a)10,6 b)10,7 c)3,6 d)3,7 e)none

13.main() {
enum months {jan=1,feb,mar,apr};
months x=jan;
if(x==1)
printf(“jan is the first month”); }
a)does not print anything b)prints : jan is the first month
c)generates compilation error d)results in runtime error (ans. (c))

14.what is the output of the following program?
Main() {
char *src=”hello world”;
char dst[100];
strcpy(src,dst);
printf(“%s”,dst); }
strcpy(char *dst,char *src) {
while (*src) *dst++=*src++; }
a)”hello world” b)”hello” c)”world” d)NULL e)undefined (ans. (e))

15.main() {
int i=6;
switch(i) {
default: i+=2;
case 4;i=4;
case 5:i++;
break; }
printf(“%d”,i); }
a)8 b)6 c)5 d)4 e)none (ans. (c))

16.main() {
int x=20;
int y=10;
swap(x,y);
printf(“%d %d”,y,x+2); }
swap(int x,int y) {
int temp;
temp=x;
x=y;
y=temp; }
a)10,20 b)20,12 c)22,10 d)10,22 e)none


17.#define INC(x) x++
main() {
int x=4;
printf(“%d”,INC(x++)); }
a)4 b)5 c)6 d)compilation error e)runtime error (ans.(d))

18.struct node{
char *word;
int count;
struct node left;
struct node right; };
a)incorrect definiton b)structures cannot refer to other structrues
c)structures can refer to themselves. Hence the statement is ok
d)structures can refer to maximum of one other structure


19.what is the size of the following union
union tag{
int a;
float b;
char c; };
a)2 b)4 c)1 d)7 (ans.(b))

20. main() {
char s[]=”hello world”;
printf(“%15.10s”,s); }
a)hello,.world… b)…..hello world c)heloo,.wor….. d)none of the above (ans.(b))

Questions by suji   answers by suji

Showing Answers 1 - 12 of 12 Answers

mohona bose

  • Mar 15th, 2006
 

Ans: 2(b) because inside the " " within printf() the values can't be changed by the macro expansion.

Sorry to correct you but I have got reference from Kanetkar's book ..Exploring C.

  Was this answer useful?  Yes

anitha

  • Jul 12th, 2006
 

hiy have mensioned that the ans for 13th ques as C.ie compilation error.but i think the prog run successfully and print jan is the first month(ie ans a)

  Was this answer useful?  Yes

umesh ram sharma

  • Sep 3rd, 2006
 

ans. of 18.) ques.

any struct object cannot be declare in itself. because at compilation time compiler has to locate the memory to the struct bt if struct has its own object in it then it is difficult to find the  size of the struct ,for compiler. pointer to own struct can be declare like

struct node{
char *word;
int count;
struct node *left;
struct node *right; };
because pointer need only 2 byte ,what ever the type of pointer. 

  Was this answer useful?  Yes

murali

  • Aug 16th, 2007
 

I totally second that. Macro substitution is not possible within the printf.

  Was this answer useful?  Yes

murali_hd

  • Aug 16th, 2007
 

struct node{
char *word;
int count;
struct node *left;
struct node *right; };
?
??????????? Well machismo.Even this code is throwing me linker errors.Could you know why?
??

  Was this answer useful?  Yes

murali_hd

  • Aug 16th, 2007
 

Nay. I dont think it works that way. I really dont know what compiler you been using. But with VC++ it sure does throw some errors. I would post those errors.

D:MSDev98MyProjectsapti_4apti_4.c(64) : error C2513: 'int ' : no variable declared before '='
D:MSDev98MyProjectsapti_4apti_4.c(65) : error C2065: 'x' : undeclared identifier
Error executing cl.exe.

?????????? Maybe you must have used "int "instead of enum x.That would correspond to the answer you mentioned in your post. Anyways do ponder about it.

main() {

int months {jan=1,feb,mar,apr};
enum x=jan;
if(x==1)
printf("jan is the first month"); }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions