1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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

Discussion in 'C' started by supoder, Aug 23, 2007.

  1. supoder

    supoder New Member

    Joined:
    Aug 23, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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[j]=0;
    OR
    for(j=0;j<10;j++)
    for(i=0;i<100;i++)
    a[j]=0;
    (a)First code
    (b)Second code
    (c)Same
    (d)Compiler and hardware dependent
     
    Last edited by a moderator: Aug 23, 2007
  2. seeguna

    seeguna New Member

    Joined:
    Jun 20, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Technical Consultant
    Location:
    Chennai
    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......
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Format your posts so that its readable at least.
     
  5. supoder

    supoder New Member

    Joined:
    Aug 23, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    And that is the reason I have done the necessary edits for you.
     

Share This Page