Strings Quiz

What does the following fragment of C-program print?

char c[] = “GATE2011”;char *p =c;printf(“%s”, p + p[3] — p[1]) ;

A. GATE2011

B. E2011

C. 2011

D. 011

Solution :

C) is correct.

char c[] = "GATE2011"; 

// p now has the base address string "GATE2011"
char *p = c;

// p[3] is 'E' and p[1] is 'A'.
// p[3] - p[1] = ASCII value of 'E' - ASCII value of 'A' = 4
// So the expression p + p[3] - p[1] becomes p + 4 which is
// base address of string "2011"
printf("%s", p + p[3] - p[1]); // prints 2011

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Application Performance Management (APM) Tools

A 5-Step Approach To Integrate Real-Time Broadcasting In Laravel

A 5-Step Approach To Integrate Real-Time Broadcasting In Laravel

Simple Webcam Application in Python Using OpenCV

Stop Starting Start Finishing — Agile Thinking — XenonStack

CDependency Injection Lifetimes in .NET

How was Imagine 2019? Recap from global Magento conference

SQL Project — Working on Hospital Database

Building An Immutable Cloud Infrastructure On Alibaba Cloud

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Dinner Hand Shakes Puzzle

Leetcode 8. String to Integer (atoi)

Window Sliding Technique |Explained Simple

One interview, Many learnings