LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
40 views
in Information Technology by (30.0k points)
closed by

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 ______.

1 Answer

0 votes
by (48.1k points)
selected by
 
Best answer

string c is:

G

A

T

E

C

S

I

T

2

0

1

7

NULL

100 101 102 103 104 105 106 107 108 109 110 111 112

\(\begin{matrix}p & \boxed{100} \\\ {} & 200 \end{matrix}\)

Character is of one byte and hence each character it placed at one byte of space .

char* p = c; // p is pointing to base address of c

2[p] = p[2]

ASCII value of T and I in decimal are is 84 and 73 respectively.

c+2[p] – 6[p]-1 = 100 + p[2] - p[6] – 1

= 100 + T – I – 1 = 100 + (84 - 73) – 1

= 100 + 11 – 1 = 110

Which means string starting from address 110 onwards till 111

So, (int)strlen (c+2[p] – 6[p]-1)

= (int)strlen(“17”)

The output of the program is 2.

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...