776 views

2 Answers

3 votes
3 votes
str = "Gate2015";

In memory

1000: G
1001: a
....
1007: 5
1008: \0

Now, str has the value 1000.
In the function, while loop terminates when P1 points to '\0' (which has integer value 0). So, P1 = 1008. And P1-P2 returns (1008-1000)/1 = 8 as size of char is 1 in C.
0 votes
0 votes
I think size of the string will be printed .... see we pass the base address of the string to madeeasy .... we store it into an initial pointer than we do while statement to find null, we increment address in between this than finally we subtract the base address with this incremented address and return.

Related questions

0 votes
0 votes
1 answer
2
Rohit Gupta 8 asked Nov 8, 2017
7,115 views
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?C = 100 for(i=0; i<n; i++) for (j=0; j<n; j++) { Temp = A[i][j] + C A[...
1 votes
1 votes
4 answers
3
Isha Karn asked Dec 9, 2014
970 views
int i = 1; int main() { int a[]= { 0,1, 2} ; f(a[i], i); printf("%d", a[i]); } void f(int x, int y) { y++; x=5*i; }In above function f() uses " call by name" technique, w...
2 votes
2 votes
2 answers
4
Isha Karn asked Dec 9, 2014
336 views
main() { int x, y= 100; float *P; P=&y; x=*P; printf("%d", x); }what is output?a) 100b) 1c) 0d) none