• closed by
2,693 views
0 0 votes
closed with the note: bad question
Consider the following program segment

int main()
{
char *str = "GATECS";
printf("%d", madeeasy(str));
return 0;
}
int madeeasy(int *p1)
{
int *p2 = p1;
while(*++p1);
return p1-p2;
}

The out of above program will be ________. Assume that the object of data type int occupies 2 bytes.

3 Answers

0 0 votes

Answer is 6. 

This function basically counts number of characters in a string.

The function madeeasy(int *p1) basically counts number of characters in input string..

Inside madeeasy(int *p1) pointer p2 is initialized as p1. 

The statement while(*++p1) increments p1 till ‘ \ 0’ is reached! p1 is incremented by 6..

Finally the difference between p1 and p2 is returned which is 6.  

0 0 votes
answer will be 3........as difference will be 6.....we will divide it by 2  as size of int pointer will be 2 bytes....thus 3....
Position:
Show:

Related questions

0 0 votes
1 1 answer
1.7k
1.7k views
Psnjit asked Jan 12, 2019
1,722 views
main(){unsigned int i= 255;char *p= &i;int j= *p;printf("%d\n", j);unsigned int k= *p;printf("%d", k);} Both the outputs are -1. I have even tried with - int i = 255(3rd ...
0 0 votes
1 1 answer
1.9k
1.9k views
Mr khan 3 asked Nov 3, 2018
1,870 views
#include<stdio.h void fun(int *p,int *q) { p=q; *p=q; } int i=0,j=1; int main() { fun(&i,&j); printf("%d%d",i,j); }What will be the output of i and j in 16-bit C Compiler...
0 0 votes
1 1 answer
1.6k
1.6k views
sushmita asked Sep 30, 2018
1,579 views
What is the interpretation of following C declaration:char *(*( foo[][8])())[];(A) foo is array of 8 pointer to pointer to function returning pointer to array of pointer ...