what will be printed by this printf?
printf("%c",printf("hi")["sharkselva"]));
}

Answer Posted / vadivelt

Ans: hia

Reason is, in the below statement,
printf("%c",printf("hi")["sharkselva"]));

printf("hi") shall be executed first. and this printf will
return the value 2. ie., no of characters successfully
printed by printf()statement.

So in runtime, "printf("%c",printf("hi")["sharkselva"]));"
will print "hi" and after, the main printf shall be
replaced as "printf("%c",2["sharkselva"]));".

According to printf() implementation, printf("%c",2
["sharkselva"]));" has to print the value at the array, for
the index given ie., 2. So in the array index '2',
character 'a' is available.

Now a is printed.

So the total output will be -> hia

Is This Answer Correct ?    31 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between malloc calloc and realloc in c?

649


Can you explain the four storage classes in C?

642


Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

582


What are static variables in c?

629


How do you print only part of a string?

613






How many types of arrays are there in c?

594


What is the usage of the pointer in c?

606


How can I remove the trailing spaces from a string?

616


What is a union?

611


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

707


What is the purpose of 'register' keyword?

691


stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

1856


How can you draw circles in C?

625


Array is an lvalue or not?

640


how is the examination pattern?

1597