ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
main( )

      {

       static int  a[ ]   = {0,1,2,3,4};

       int  *p[ ] = {a,a+1,a+2,a+3,a+4};

       int  **ptr =  p;

       ptr++;

       printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr); 

       *ptr++;

       printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr); 

       *++ptr;

    printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr); 

    ++*ptr;

	 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr); 

      }
 Question Submitted By :: Susie
I also faced this Question!!     Rank Answer Posted By  
 
  Re: main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }
Answer
# 1
Answer : 

      	111

      	222

      	333

      	344

      Explanation:

Let us consider the array and the two pointers with some address

   a	

0
1
2
3
4
         100      102      104      106      108

					     p

100
102
104
106
108
  			   1000    1002    1004    1006    1008

	     ptr	

1000
2000

After execution of the instruction ptr++ value in ptr
becomes 1002, if scaling factor for integer is 2 bytes. Now
ptr – p is value in ptr – starting location of array p,
(1002 – 1000) / (scaling factor) = 1,  *ptr – a = value at
address pointed by ptr – starting value of array a, 1002 has
a value 102  so the value is (102 – 100)/(scaling factor) =
1,  **ptr is the value stored in the location pointed by 
the pointer of ptr = value pointed by value pointed by 1002
= value pointed by 102 = 1. Hence the output of the firs
printf is  1, 1, 1.

After execution of *ptr++ increments value of the value in
ptr by scaling factor, so it becomes1004. Hence, the outputs
for the second printf are ptr – p = 2, *ptr – a = 2, **ptr = 2. 

After execution of *++ptr increments value of the value in
ptr by scaling factor, so it becomes1004. Hence, the outputs
for the third printf are ptr – p = 3, *ptr – a = 3, **ptr = 3. 

After execution of ++*ptr value in ptr remains the same, the
value pointed by the value is incremented by the scaling
factor. So the value in array p at location 1006 changes
from 106 10 108,. Hence, the outputs for the fourth printf
are ptr – p = 1006 – 1000 = 3, *ptr – a = 108 – 100 = 4,
**ptr = 4.
 
Is This Answer Correct ?    0 Yes 0 No
Susie
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }  1
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above HCL1
how to check whether a linked list is circular.  3
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) Disney3
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }  1
main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }  1
main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above HCL1
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }  1
main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }  1
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }  1
main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }  1
main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(“%d” ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(“%d ” ,*p); p++; } }  1
What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }  1
char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }  1
What is the output for the following program main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }  1
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }  1
Find your day from your DOB? Microsoft12
how can u draw a rectangle in C Wipro31
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)  1
main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com