The Gateway to Computer Science Excellence
+1 vote
int main(void) {
char *a="MADEEASY";
char *b="GATECSIT2019";
char *r=a;
char *s=b;
return 0;

Ans is given $8.$ I know basic thing, but couldnot getting what strlen(b+3[r]-1[s]) returning?? Plz explain.

in Programming by Veteran (117k points) | 123 views

1 Answer

+4 votes
Best answer

strlen(b+3[r]-1[s]) :

first: 3[r] is same as r[3] i.e., 'E'

and 1[s] is same as s[1] i.e., 'A'

3[r] - 1[s] = 'E' - 'A' = 4

now, b + 4 refers to  4 th index in b i.e, 'C' (starting position)

strlen(b+4) = strlen("CSIT2019") = 8

Thus, it will return 8.

correct me if i am wrong.

by Junior (609 points)
selected by
But Arithmetic operator is Left to right associativity.

so why you evaluate the right first ?
yes, but it won't differ.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,648 questions
56,455 answers
100,134 users