edited by
771 views
0 votes
0 votes
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);
}

output is 76 pls explain.

edited by

1 Answer

2 votes
2 votes

1) char s[]={'a','b','c','\n','c','\0'}; 

by this line s is array of characters created at location 100 ( assume)

'a' 'b' 'c' '\n' 'c' '\n'
100 101 102 103 104 105

 

2) char *p,*str,*str1; 

 by this line you are declaring p is pointer to character, str is pointer to character, str1 is pointer to character

 

3) p=&s[3]; 

by this line p is get value as memory address of 3rd index of s ===> p = 103


4)str=p; 
by this line str also get value as memory address of 3rd index of s ===> str = 103

 

5) str1=s; 

by this line str1 get value as memory address of 0th index of s ===> str1 = 100


6) ++*p+++*str1-32  =====>  (++*p+++*str1) - ( 32 )   =====>  (  (++ ( * (p ++) ) )  + ( * str1) ) - ( 32 ) 

p is post increment ===> no change in that statement ===> p=103 ===> *p = value at 103 ==> '\n'

(++ ( * (p ++) )  ===> increment the value = '\n' + 1 ===> ascii value of '\n' +1 = 10+1 =11 

 

(++*p+++*str1) - ( 32 )  = 11 + 'a' - 32 ===> 11+97-32 = 108 - 32 = 76

Related questions

517
views
1 answers
3 votes
GO Classes asked Apr 30, 2022
517 views
What will be the output of the following C program?#include<stdio.h> int main() { static int p[] = {1, 2, 3, 0, 5, 6}; static int *q[] = {p+2, p+1, p, p+3, p+4, p+5}; ... q+3}; int ***pt; pt = r + 2; printf("%d", ***(pt+3)-**(q+1)); }