Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – Table Lookup

C Programming Questions and Answers – Table Lookup

1.What is the output of this C code?

#include <stdio.h>

struct student

{

char a[5];

};

void main()

{

struct student s[] = {“hi”, “hey”};

printf(“%c”, s[0].a[1]);

}

a) h

b) i

c) e

d) y

View Answer

Answer:b

2.What is the output of this C code?

#include <stdio.h>

void main()

{

char *a[3] = {“hello”, “this”};

printf(“%s”, a[1]);

}

a) hello

b) Varies

c) this

d) Compile time error

View Answer

Answer:c

3.What is the output of this C code?

#include <stdio.h>

void main()

{

int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

printf(“%d”, lookup[3]);

}

a) 2

b) 4

c) Compile time error

d) 3

View Answer

Answer:d

4.What is the output of this C code?

#include <stdio.h>

void main()

{

char *a[3][3] = {{“hey”, “hi”, “hello”}, {“his”, “her”, “hell”}

, {“hellos”, “hi’s”, “hmm”}};

printf(“%s”, a[1][1]);

}

a) her

b) hi

c) Compile time error

d) hi’s

View Answer

Answer:a 

5.What is the output of this C code?

#include <stdio.h>

struct p

{

char *name;

struct p *next;

};

struct p *ptrary[10];

int main()

{

struct p p;

p->name = “xyz”;

p->next = NULL;

ptrary[0] = &p;

printf(“%s\n”, p->name);

return 0;

}

a) Compile time error

b) Segmentation fault/code crash

c) xyz

d) Undefined behaviour

View Answer

Answer:a

6.What is the output of this C code?

#include <stdio.h>

struct p

{

char *name;

struct p *next;

};

struct p *ptrary[10];

int main()

{

struct p p;

p.name = “xyz”;

p.next = NULL;

ptrary[0] = &p;

printf(“%s\n”, ptrary[0]->name);

return 0;

}

a) Compile time error

b) Segmentation fault

c) Undefined behaviour

d) xyz

View Answer

Answer:d 

7.What is the output of this C code?

#include <stdio.h>

struct p

{

char *name;

struct p *next;

};

struct p *ptrary[10];

int main()

{

struct p p, q;

p.name = “xyz”;

p.next = NULL;

ptrary[0] = &p;

strcpy(q.name, p.name);

ptrary[1] = &q;

printf(“%s\n”, ptrary[1]->name);

return 0;

}

a) Compile time error

b) Segmentation fault/code crash

c) Depends on the compiler

d) xyz

View Answer

Answer:b

8.What is the output of this C code?

#include <stdio.h>

int main()

{

struct p

{

char *name;

struct p *next;

};

struct p p, q;

p.name = “xyz”;

p.next = NULL;

ptrary[0] = &p;

strcpy(q.name, p.name);

ptrary[1] = &q;

printf(“%s\n”, ptrary[1]->name);

return 0;

}

a) Compile time error

b) Depends on the compiler.

c) Undefined behaviour

d) xyz

View Answer

Answer:c

9.Which function is responsible searching in the table?

(For #define IN 1, the name IN and replacement text 1 are stored in a “table”)

a) findout(s);

b) lookup(s);

c) find(s);

d) lookfor(s);

View Answer

Answer:b

10.Which algorithm is used for searching in the table?

a) List search

b) Informed search

c) Hash search

d) Adversarial search

View Answer

Answer:c

11.Which function is responsible for recording the name “s” and the replacement text “t” in a table?

a) install(s, t);

b) fix(s, t);

c) setup(s, t);

d) settle(s, t);

View Answer

Answer:a

12.Which of the following is true?

a) Install function uses lookup

b) lookup function uses install

c) Install and lookup function work independently

d) Both (a) as well as (b)

View Answer

Answer:a

13.What happens when install(s, t) finds that the name being installed is already present in table?

a) It doesn’t modify the name in the table

b) It modifies the name with new definition

c) It modifies iff the new definition has higher priority

d) It creates a new table and add the new definition in it

View Answer

Answer:b

14.In what situation, install function returns NULL?

a) When there is no memory for adding new name

b) When the name to be defined is already present in the table

c) Whenever a new name is added to the table

d) All of the mentioned

View Answer

Answer:a

15.What is the output of this C code?

#include <stdio.h>

struct student

{

char a[];

};

void main()

{

struct student s;

printf(“%d”, sizeof(struct student));

}

a) Compile time error

b) 8

c) 1

d) Varies

View Answer

Answer:a

16.What is the output of this C code?

#include <stdio.h>

int main()

{

struct p

{

char *name;

struct p *next;

};

struct p *ptrary[10];

struct p p, q;

p.name = “xyz”;

p.next = NULL;

ptrary[0] = &p;

q.name = (char*)malloc(sizeof(char)*3);

strcpy(q.name, p.name);

q.next = &q;

ptrary[1] = &q;

printf(“%s\n”, ptrary[1]->next->next->name);

}

a) Compile time error

b) Depends on the compiler.

c) Undefined behaviour

d) xyz

View Answer

Answer:d

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button