closed by
1,037 views
0 votes
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.
closed by

3 Answers

0 votes
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 votes
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....

Related questions

0 votes
0 votes
1 answer
1
Psnjit asked Jan 12, 2019
1,137 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 votes
0 votes
1 answer
2
Mr khan 3 asked Nov 3, 2018
978 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...