C interview questions part 2

1.Can you have both const and volatile qualifiers for single declaration in C? If so ,can you give me an example? If no, why not?

Ans: Yes we can have because if you want the value not to be changed by program and driver will change the value you can use this technique. Actually volatile qualifier is just to tell compiler that don’t do any code compaction since the value may be modified by another source

Ex:

volatile const int variable1 = 0;
int main()
{
printf(“variable1 %d\n”,variable1);

return 0;
}

2.Consider the following code snippet:

main()

{

int a,b;

a=foo();

b=foo()’

printf(“a=%d and  b=%d”,a,b);

return(0);

}

you don’t know anything about function ‘foo’except it returns integer.

Are the values of a and b printed by printf function the same?If not can you give an example of function ‘foo’ which will cause a and b different?

Ex:

They need not be if the function is as follows

int foo()

{

int temp;

scanf(“%d”,&temp);

return(temp);

}

3.Given a word can you find all its anagrams? If you were asked to do this solutions only one word what would be your solution if it you were asked to find the anagrams for 10000 words would your solution change?

Ans:

(If any one of you know the solution please tell me)

but my solution would be maintain database of words in the language and search the combinations occurence.

4.What is complexity of searching an element in a

a) Linked list containing N elements

Ans: normally requires O(n) time (linear search).

b)Hash table containing N elements

Ans: log(n)

c)Binary search tree containing N elements

Ans: log(n)

d)A binary heap tree containing N elements

Ans: log(n)

e)A d-heap containing N elements

Ans: log(n)

5.Consider the following code snippet :

int find_fib(int N)

{

asser(N > 0);

int f1=1;

int f2=1;

 

if(N<2)

return(1);

return(find_fib(N-1)+find_fib(N-2));

}

given that find_fib is called from main with N as 25 how many total calls are made to find_fib?

Ans : 26

6. you are given an arry of 2n+1 integers. You are told that except one element all other elements have duplicate in the array? what is the time complexity of your solution?

Ans:

Sort the integers in ascending order and search element and search for the element so

1.Can you have both const and volatile qualifiers for single declaration in C? If so ,can you give me an example? If no, why not?

Ans: Yes we can have because if you want the value not to be changed by program and driver will change the value you can use this technique. Actually volatile qualifier is just to tell compiler that don’t do any code compaction since the value may be modified by another source

Ex:

volatile const int variable1 = 0;
int main()
{
printf(“variable1 %d\n”,variable1);

return 0;
}

2.Consider the following code snippet:

main()

{

int a,b;

a=foo();

b=foo()’

printf(“a=%d and  b=%d”,a,b);

return(0);

}

you don’t know anything about function ‘foo’except it returns integer.

Are the values of a and b printed by printf function the same?If not can you give an example of function ‘foo’ which will cause a and b different?

Ex:

They need not be if the function is as follows

int foo()

{

int temp;

scanf(“%d”,&temp);

return(temp);

}

3.Given a word can you find all its anagrams? If you were asked to do this solutions only one word what would be your solution if it you were asked to find the anagrams for 10000 words would your solution change?

Ans:

(If any one of you know the solution please tell me)

but my solution would be maintain database of words in the language and search the combinations occurence.

4.What is complexity of searching an element in a

a) Linked list containing N elements

Ans: normally requires O(n) time (linear search).

b)Hash table containing N elements

Ans: log(n)

c)Binary search tree containing N elements

Ans: log(n)

d)A binary heap tree containing N elements

Ans: log(n)

e)A d-heap containing N elements

Ans: log(n)

5.Consider the following code snippet :

int find_fib(int N)

{

asser(N > 0);

int f1=1;

int f2=1;

 

if(N<2)

return(1);

return(find_fib(N-1)+find_fib(N-2));

}

given that find_fib is called from main with N as 25 how many total calls are made to find_fib?

Ans : 26

6. you are given an arry of 2n+1 integers. You are told that except one element all other elements have duplicate in the array? what is the time complexity of your solution?

Ans:

Sort the integers in ascending order and search element and search for the element so

1.Can you have both const and volatile qualifiers for single declaration in C? If so ,can you give me an example? If no, why not?

Ans: Yes we can have because if you want the value not to be changed by program and driver will change the value you can use this technique. Actually volatile qualifier is just to tell compiler that don’t do any code compaction since the value may be modified by another source

Ex:

volatile const int variable1 = 0;
int main()
{
printf(“variable1 %d\n”,variable1);

return 0;
}

2.Consider the following code snippet:

main()

{

int a,b;

a=foo();

b=foo()’

printf(“a=%d and  b=%d”,a,b);

return(0);

}

you don’t know anything about function ‘foo’except it returns integer.

Are the values of a and b printed by printf function the same?If not can you give an example of function ‘foo’ which will cause a and b different?

Ex:

They need not be if the function is as follows

int foo()

{

int temp;

scanf(“%d”,&temp);

return(temp);

}

3.Given a word can you find all its anagrams? If you were asked to do this solutions only one word what would be your solution if it you were asked to find the anagrams for 10000 words would your solution change?

Ans:

(If any one of you know the solution please tell me)

but my solution would be maintain database of words in the language and search the combinations occurence.

4.What is complexity of searching an element in a

a) Linked list containing N elements

Ans: normally requires O(n) time (linear search).

b)Hash table containing N elements

Ans: log(n)

c)Binary search tree containing N elements

Ans: log(n)

d)A binary heap tree containing N elements

Ans: log(n)

e)A d-heap containing N elements

Ans: log(n)

5.Consider the following code snippet :

int find_fib(int N)

{

asser(N > 0);

int f1=1;

int f2=1;

 

if(N<2)

return(1);

return(find_fib(N-1)+find_fib(N-2));

}

given that find_fib is called from main with N as 25 how many total calls are made to find_fib?

Ans : 26

6. you are given an arry of 2n+1 integers. You are told that except one element all other elements have duplicate in the array? what is the time complexity of your solution?

Ans:

Sort the integers in ascending order and search element and search for the element so

Θ((2n+1)log(2n+1))(sort) + n+1(search)

 

6 thoughts on “C interview questions part 2

స్పందించండి

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / మార్చు )

Twitter picture

You are commenting using your Twitter account. Log Out / మార్చు )

Facebook photo

You are commenting using your Facebook account. Log Out / మార్చు )

Google+ photo

You are commenting using your Google+ account. Log Out / మార్చు )

Connecting to %s