URDINESH: C and Data Structures Interview Questions Collections
Showing posts with label C and Data Structures Interview Questions Collections. Show all posts
Showing posts with label C and Data Structures Interview Questions Collections. Show all posts

Thursday, May 8, 2014

Objective C Debugging Questions and Answers part 1

1)      Point out the error, if any, in the following program.
#include<stdio.h>
main()
{
                  int i=1,j=2;
                  switch(i)
                  {
                              case 1:
                                          printf(“Good”);
                                          break;
                              case j:
                                          printf(“Bad”);
                                          break;
                  }
}
(a) Error     (b)Good          (c)Bad             (d)GoodBad
ANS :(a)Error

2)      Find the output for the given program.
#include<stdio.h>
main()
{
            int i=4z=12;
            if(i=5&&z>5)
            printf(“\nLet us C”);
            else
            printf(“\nwish C was free”);
}
(a)Let us C      (b)wish C was free      (c)Error            (d)No output
ANS :(a)Let us C

3)      What would be the output of the given program?
#include<stdio.h>
main()
{
            int big,a,b,c;
            a=2,b=3,c=4;
            big=(a>b?(a>c?3:4):(b<c?6:8));
            printf(“%d”,big);
}
(a)Error            (b)3      (c)6      (d)8
ANS :(d)8

4)      Find the output for the given program.
#include<stdio.h>
main()
{
            extern int i;
            i=20;
            printf(“%d”,i);
}
(a)20    (b)Compile Error         (c)0      (d)Linker Error
ANS :(d)Linker Error

5)      What would be the output for the given program?
#include<stdio.h>
main()
{
            int a=10,*j;
            void *k;
j=k=&a;
j++;
k++;
printf(“\n%u%u”,j,k);
}
(a)10,11           (b)0      (c)Linker Error            (d)Compiler Error
ANS :(d)Compiler Error

6)      Check out the answer for the given program.
#include<iostream.h>
main()
{
            int x=77;
            float y=5.1252;
            char z=’A’;
            char city[15];
            cout<<”x=”<<(char)x<<endl;
            cout<<”y=”<<(int)y<<endl;
            cout<<”z=”<<(int)z;
}
(a)65,5,M        (b)M,5,65        (c)Compiler Error        (d)Linker Error
ANS :(b)M,5,65

7)      What would be the output of the following program?
#include<stdio.h>
#define PRODUCT(X) (X*X)
void main()
{
            int i=3,j,k;
            j=PRODUCT(i++);
            k=PRODUCT(++i);
            printf(“\n%d%d”,j,k);
}
(a)3,4               (b)9,9               (c)49,5             (d)9,49
ANS :(d)9,49

8)      Find the output for the given program.
#include<stdio.h>
main()
{
            int i=10;
            i=!i>14;
            printf(“i=%d”,i);
}
(a)i=13             (b)i=10            (c)i=0               (d)No output
ANS :(c)i=0

9)      Find the output for the given program.
#include<stdio.h>
main()
{
            int k=35,*z,*y;
            z=&k;
            y=z;
            *z++=*y++;
            k++;
            printf(“k=%d z=%d y=%d”,k,z,y);
}
If suppose address of k is 1000. what is the value of k,z,y?
(a)k=36 z=-10 y=-10                           (b)k=1010 z=1012 y=35                    
(c)k=1012 z=1010 y=1008                 (d)None
ANS :(a)k=36 z=-10 y=-10

10)  Find the answer for the following program.
#include<iostream.h>
void main()
{
            char c;
            cout<<”Enter text(press F6 to end)”;
            while(cin.get())
            {
                        if(c==’s’)
                        cin.putback(‘s’);
                        cout.put(c);
                        }
                        return 0;
}
If input is “cplusplus”
(a)cpluss          (b)Error           (c)No output               (d)cplusspluss
ANS :(d)cplusspluss

11)  Find out the output for the given program.
#include<stdio.h>
main()
{
            int a=2,*f1,*f2;
            f1=f2=&a;
            *f2+=*f2+=a+=2.5;
            printf(“\n%d%d%d”,a,*f1,*f2);
}
(a)2.5,2.5,2.5   (b)16.5,16.5,16.5         (c)15.5,15.5,15.5         (d)16,16,16
ANS :(d)16,16,16

12)  What would be the output for the following program?
#include<stdio.h>
main()
{
            int i=300;
            char *ptr=&i;
            *++ptr=2;
            printf(“%d”,i);
}
(a)302              (b)119              (c)556              (d)298
ANS :(c)556

13)  Find the output for the following program.
#include<iostream.h>
main()
{
            char text[20];
            int len;
            cout<<”Enter text:”;
            cin.getline(text,20);
            len=cin.getcount();
            cout<<len;
}
If text is virtual, what is ouput of len?
(a)6                  (b)7                  (c)8                  (d)Error
ANS :(c)8

14)  Find the output of the following  program.
#include<stdio.h>
main()
{
            enum colors{BLACK,BLUE,GREEN};
            printf(“%d..%d..%d”,BLACK,BLUE,GREEN);
}
(a)0..1..2          (b)2..5..6          (c)Undeclared variables          (d)None
ANS:(a)0..1..2

15)  What would be the output for the following program?
#inlcude<stdio.h>
main()
{
            int i;
            printf(“%d”,scanf(“%d”,&i));//value 10 is given as input
}
(a)1                  (b)10                (c)Linker Error                        (d)Compiler Error
ANS :(a)1


16)  What would be the output for the following program?
#include<iostream.h>
main()
{
            unsigned int=65536;
            cout<<”x=”<<x;
}
(a)0                  (b)Garbagevalue          (c)Error            (d)65536
ANS :(a)0

17)  What is the output for the given program?
#include<stdio.h>
main()
{
            int i=10;
            i=i>14;
            printf(“\n%d”,i);
}
(a)1                  (b)10                (c)0                  (d)14
ANS :(c)0

18)  Find the output of the following  program.
#include<stdio.h>
main()
{
            char not;
            not=!2;
            printf(“%d”,not);
}
(a)1                  (b)0                  (c)Error                        (d)No output
ANS :(b)0

19)  What would be the output for the given program?
#include<iostream.h>
void main()
{
            int a=2,*pa,*ra;
            pa=&a;
            ra=a;
            cout<<”a=”<<a<<”*pa=”<<*pa<<”ra=”<<ra;
}
(a)Compiler Error        (b)Linker Error            (c)No output       (d)None of this
ANS :(a)Compiler Error

20)  What is the output of the following program?
#include<stdio.h>
main()
{
            int i;
            i=1;
            i=i+2 * i++;
            printf(“%d”,i);
}
(a)5                  (b)2                  (c)4                  (d)3
ANS :(c)4

21)  What would be the output of the following program?
#include<stdio.h>
main(0
{
            char *str1=”abcd”;
            char *str2=”abcd”;
            printf(“%d%d%d”,sizeof(str1),sizeof(str2),sizeof(“abcd”));
}
(a)144              (b)244              (c)255              (d)155
ANS :(c)255

22)  Find the output for the given program.
#include<stdio.h>
main()
{
            int c=--2;
            printf(“c=%d”,c);
}
(a)c==-2          (b)c=2             (c)Error            (d)Garbage value
ANS :(c)Error

23)  What would be the output of the given program?
#include<stdio.h>
main()
{
            int i,j
            for(i=0;i<=10;i++)
            {
                        j+=5;
                        assert(i<5);
            }
}
(a)Linking Error          (b)Compiler Error        (c)No output   (d)Runtime Error
ANS :(a)Linking Error

24)  Find the output for the given program.
#include<stdio.h>
main()
{
            char *p=”hai friends”,*p1;
            p1=p;
            while(*p!=’/0’)++*p++;
            printf(“%s%s”,p,p1);
}
(a)Error            (b)ibj!gsjfoet               (c)No output   (d)None of these
ANS :(c)No output

25)  What would be the output for the given program?
#include<stdio.h>
#include<conio.h>
main()
            {
                        clrscr();
                        printf(“%d\n”,clrscr());
}
(a)Error            (b)100  (c)Compiler Error        (d)Infinite Loop
ANS :(b)100

26)  Check out the answer for the given program.
#include<stdio.h>
main()
{
            printf(“\nab”);
            printf(“\bsi”);
            printf(“\nrna”);
           
}
(a)hai               (b)absina          (c)ab sina         (d)sp abha
ANS :(a)hai

27)  What would be the output of the following program?
#include<stdio.h>
void main()
{
            while(1)
            {
                        if(printf(“%d”,printf(“%d”)))
                        break;
                        else
                        continue;
}
(a)0                  (b)2                  (c)1      (d)Garbagevalue
ANS :(d)Garbagevalue

28)  Find the output for the given program.
#include<stdio.h>
void main()
{
            void *v;
            int integer=2;
            int *i=&integer;
            v=i;
            printf(“%d”,(int*)*v);
}
(a)2                  (b)0                  (c)Compiler Error                    (d)Linker Error
ANS :(c)Compiler Error

29)  Find the output for the given program.
#include<stdio.h>
main()
{
            int i=257;
            int *iPtr=&i;
            printf(“%d%d”,*((char*)iPtr),*((char*)iPtr+1));       
}
 (a)10,11          (b)257,257       (c)257,752                   (d)1,1
ANS :(d)1,1

30)  Find the answer for the following program.
#include<stdio.h>
 main()
{
                        int y[4]={6,7,8,9};
                        int *ptr=y+2;
                        printf(“%d\n”,ptr[1]);
}
(a)6      (b)7      (c)8                  (d)9

ANS :(d)9





                 *******Thank you for reading and All the best**************

Your comments will help me a lot...please give your comments which will encourage me to post more.....

C and Data Structures Interview Questions Collections


General C Questions
*******************

How C program compiles and linking ?
GCC and it's options, what is make file ?

What is volatile ? Why we go for vollt ? What is optimization ?
Example program of volatile ? Applications using volatile variable ? Where it will store in RAM ? Can a variable be both const and volatile?

What is Static ? applications of static keyword ? if i extern a static variable, which stage that error will be identified ? Scope ?

Different type of datatypes ? int,uint,char.. long ?
What if do multiply unit,int ? that cast conversion is needed ?

What is the application of const qualifier ?

What is reg data type ? where you use it ? Scope ?

All mem related functions like memcpy, memmove,
memchr, memset, bzero ? Esxpecially How do you find overlap in memmove and how do you copy data from src to dest ?

Swap two variables without using temp, ExoR, single line, using +,-

How does free() knows allocated memory ?

How do you define a variable argument function ? Use va_arg, va_start,va_end macros.

How do you find the size of a variable without using sizeof opr?

What is recursion and applications of recursive ?

Get the inputs like 10,20,30,40,50 and print it in reverse order, Dont use array. Dont expect Stack-LinkedList implementation. Use recursive method.
Four parts of RAM and what are the variables stored in all fours parts? BSS ? How BSS value gets intialized ?
How do you print value stores in 0x00123 address ? Can we assign the address to a pointer ? Might be in DOS, far pointer concepts.
How do you avoid twice inclusion of same header file ? using #if define
Write a program to find the square root of the number without using the any mathematical function ?

Is size of int depends on machine or compiler ? size of pointer ?



ARRAY:
******
In an array, linear search, binary search,
How do you find duplicate in an array and remove it ?
Addition/Deletion of an element in an array at n th position ?
Reverse of an array[string,int]
sorting an array[bubble,select,...look DS Questions]
Memory allocation for single dimension array, two dimentsional array, three dimension array using malloc. Differnt ways of allocation memory for 2 dimen array.
How do you pass all the arrays to a func ?
How do you intialize all the dimensional arrays ? What is the value of other location if the array is partially initialized ?
static array means ? application ?
Array of pointers, pointer to an array ? array of funtion pointers ?
How do you intialize above pointers ?
Matrix addition, multiplications.


STRING:
*******
Defintions for all string handling functions like 
strlen,strcpy,strncpy,strcat,strncat,strstr,strrev
strrev - using recursive, without any buffer
strstr - own defintions
strcmp - ow defn
Reverse the words from a statement ? I am a boy==> boy a am I
insert word in between given string
Where string constant will store ? scope of that const ?
Find out the no of words,lines,chars in a given file ?
find the length of given string buffer, without using loop and str func. Use printf


FUNCTION:
*********
function pointer ? different set of fptr declarations ?
know the spiral rule ? declare a fptr returns fptr itself ?
call by value/call by reference
Stack is related to a func or a process[Moto] ?
How does the stack grows when a f1 calls f2 ? Draw and explain how local var, return add is being stored ? SP,PC reg ?
argc,argv means ? usage of that variables ?
What is function prototype ?
What is inline func and why do we need ?
what is reentrant function ? where it stores ?
Write a function to add two 16-bit numbers it will return
      TRUE  -  in case of overflow in the result
      FLASE - if there is no overflow
How do you manage 2 stacks using single array of buffer ?




BITWISE OPERATIONS:
*******************
How do you set/reset a bit in an integar ?
Count of no of bits set in an int ?
Reverse the bits in an int ?
Find out the given no id odd/even and power of two ?
What is little/big endian, find out machine endian ?
Convert big to little endian and viceversa ? ntoh ? hton ?
Multiply the given two nos withoug using * ?
Swap two bits in an integar ?
Convert int<->binary int to hex, int to hex, Get to know the common function definition.
Sum of digits of given no ? Palindrome ?


STRUCTURE AND UNION:
*********************
Difference btw struct and union ?
Struct padding ? How do you avoid ? Size of given struct ?
__attribute__() and #define pragma pack(1)
Recursive struct declaration ?
Can we have union under union ?
How do you have structure pointer in it's own structure ?
Array of structures ? passings struct into a function ?
Find out the offset of given struct member, when u have no pointer to that struct ?


POINTERS:
**********
Applications of pointer ? Speciality of pointer ?
Pointer addition/deletion.
Allocate memory to pointer ?
typecasting pointers ?
Pointer to single,two,three dimensional arrays ? memory allocate ?
pointer with const qualifier ? conts int *a, int *const a diff ?
A function which defines a 2D array and return pointer, The caller able to get the address and can access it. Write a program.
Size of pointer ?
What is FILE pointer ? How it's being used ?
What is NULL pointer ? void pointer ?


Difference Questions 
*********************
Diff btw enum constant and #define const ?
Diff btw inline func and #define func ?
Diff btw #ifdef and #if define ?
Diff btw char const and string const ?
Diff btw declaration and definitions ?
Diff btw #include "" and <> ?
Diff btw auto,static,reg,extern ?
Diff btw malloc,calloc ?
Diff btw pointers and arrays ?


DATA STRUCTURES:
*****************
[STACK,QUEUE,LINKEDLIST,HASHING,BINARYTREE,SEARCH,SORTING]

Stack [implement using LL,array]
    Push,Pop,Peep,
Queue [implement using LL,array]
    Insert,Delete,
Circular Queue[using LL and array]
    Add/Delete/Searching/
Priority Queue[Arrays, LL]
    Add/Delete
Linked List:- Single/double
    Addition,Deletion - (start,end,middle,nth position,count)
    [ascend/descend order] copy LL, Delete LL, Append 2 LL
    reverse,recursive_Reverse,Sorting,concat2list,remove duplicates,
    delete_current_node(no head pointer available)
    insert/delete n th element from last.
    How do you convert doubly linked list to single without using
    structures?
    In which data structure, elements can be added or removed at
    either end, but not in the middle? Dequeue
    Find out the character that repeats itself in a big arrays[1000
    characters in it]
    What is the most efficient way of finding a loop in linklist.
    Add element in the middle of LL with single traversal.
Binary Tree
    Add/Delete/print(inorder,preorder,postorder)
    Application/ -Arithmetic Expresssion, SymbolTable
    construction,Syntax analysis.
    What is No of nodes/depth/size of tree relations.
AVL Tree
    Add/Delete/
    Application
Searching
    Linear,Divide&conquer,BinarySearch
Sorting
    Bubble,Selection,Quick,Merge,
HASH - Addition/Deletion/Applications.




Followers