The Gateway to Computer Science Excellence
+34 votes
8.4k views

Consider the following C program.

#include<stdio.h>
#include<string.h>
int main() {
    char* c=”GATECSIT2017”;
    char* p=c;
    printf(“%d”, (int)strlen(c+2[p]-6[p]-1));
    return 0;
}

The output of the program is _______

in Programming by Active (1.6k points)
edited by | 8.4k views
+2
In que. it was asked about strlen that would be 2
0
what was actual que . does this contain both printf line .......
0
Actual one had strlen wala .
0
i will just explain this wait for 5 min .....
+1
"(int)" is it use for type casting???
0
Acc to me, the value at address 110 is 1 not 7 ,how you have taken 7 which is at 111

9 Answers

0 votes

Easiest method:

c + 2[p] -6[p] -1
= c + p[2] –p[6] -1
= c + T – I – 1
= c + 11 -1
= c + 10
strlen(17) = 2

Source: https://www.geeksforgeeks.org/gate-cs-2017-set-2-gq/ -- explanation of Q.53

by Active (1.1k points)
Answer:

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,654 questions
56,166 answers
193,872 comments
94,261 users