Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   hii im new to this forum i need some c question to be sovled with reasons (http://www.go4expert.com/forums/hii-im-forum-i-c-question-sovled-reasons-t5994/)

supoder 23Aug2007 12:21

hii im new to this forum i need some c question to be sovled with reasons
 
hii

char const *p = 'd';
Which of the following is not a permissible operation
(a) *p++
(b) ++p
(c) (*p)++
(d) All

2.What is the output of the following code:-
Code:

void print_arr(float **p)
{
        printf(" 0 %f 1 %f 2 %f\n",p[0][0],p[0][1],p[0][2]);
}
void main()
{
        float arr[2][3] = {{0,1,2},{3,4,5}};
        float **fl_arr;
        fl_arr = (float *)arr;
        print_arr(fl_arr);
        fl_arr++;
        print_arr(fl_arr);
}

(a)
(d)segmentation fault

3.What is the output of the following code:-
Code:

#define putchar (c) printf("%c",c)
void main()
{
        char s='c';
        putchar (s);
}

(a) c
(b) 99
(c) Compilation error
(d) Execution error

4.What is the output of the following code:-
Code:

void main()
{
        printf("%d",printf("ABC\\"));
}

(a) ABC\\
(b) 1
(c) ABC\4
(d) ABC\3

5.What is the output of the following code:-
Code:

int compute(int n)
{
        if(n>0)
        {
                n=compute(n-3)+compute(n-1);
                return(n);
        }
        return(1);
}
void main()
{
        printf("%d",compute(5));
}

(a) 6
(b) 9
(c) 12
(d) 13

6.What is the output of the following code:-
Code:

void main()
{
        int i;
        for(i=0;i<3;i++)
        {
                int i=100;
                i--;
                printf("%d..",i);
        }
}

(a0..1..2..
(b)99..98..97..
(c)100..100..100..
(d)99..99..99..

7.What is the output of the following code:-
Code:

void main()
{
        int a[]={9,4,1,7,5};
        int *p;
        p=&a[3];
        printf("%d",p[-1]);
}

(a)6
(b)1
(c)7
(d)Error

8.What is the output of the following code:-
Code:

void main()
{
        int a[]={10,20,30,40,50};
        int *p;
        p= (int*)((char *)a + sizeof(int));
        printf("%d",*p);
}

(a)10
(b)20
(c)30
(d)40

9.Which code will run faster
for(i=0;i<100;i++)
for(j=0;j<10;j++)
a[i][j]=0;
OR
for(j=0;j<10;j++)
for(i=0;i<100;i++)
a[i][j]=0;
(a)First code
(b)Second code
(c)Same
(d)Compiler and hardware dependent

seeguna 23Aug2007 13:48

Re: hii im new to this forum i need some c question to be sovled with reasons
 
I provided answer for some questions .........


Question 3,
Trim the space between ur function name and arguments
putchar (c) can be replaced as putchar(c) for better result


Question 4
Answer is ABC\4(4 indicates no of characters printed)

Question 7

p=&a[3], so p[0]=7,p[1]=5,p[-1]=1,p[-2]=4,p[-3]=9


Remaing questions(Eventhough this too)questions were simple in nature........
if u had any more doubts..........
Mail me......

DaWei 23Aug2007 16:50

Re: hii im new to this forum i need some c question to be sovled with reasons
 
Before you make a query...

shabbir 23Aug2007 17:17

Re: hii im new to this forum i need some c question to be sovled with reasons
 
Format your posts so that its readable at least.

supoder 23Aug2007 23:22

Re: hii im new to this forum i need some c question to be sovled with reasons
 
Quote:

Originally Posted by DaWei


thanx bt this ws mah first xposure to forums

shabbir 24Aug2007 08:21

Re: hii im new to this forum i need some c question to be sovled with reasons
 
Quote:

Originally Posted by supoder
thanx bt this ws mah first xposure to forums

And that is the reason I have done the necessary edits for you.


All times are GMT +5.5. The time now is 09:16.