Answer is NING.
how....? i am not getting. can any one explain please....?

‪#‎inclde‬<stdio.h>
void main()
{
    printf(2+"GOOD EVENING"+6);
    getch();
}

Recommended Answers

All 5 Replies

Not quite sure what you plan to acheive with that syntax.

If you are trying to format the output, read this.

It skips the first 6+2 characters/bytes of the string by moving the pointer (since the string's value is stored in contiguous memory locations) => GOOD EVENING.

Not sure where you got that syntax from. It is truncating 8 characters from your string though. And it works on 2 different compilers.

"GOOD EVENING" is an array of characters. If you take any array or pointer and write p + i, you get a pointer pointing to the address that's i elements after the location that p points to. So in case of an array, arr + i (or i + arr - order doesn't matter) produces a pointer to the element of the array arr at index i.

So 2 + "GOOD EVENING" produces a pointer that points to the second O in GOOD. Adding 6 to that moves the pointer 6 further to the right, producing a pointer that points to the first N in EVENING - same as if you had written "GOOD EVENING" + 8. So you pass a pointer to that N to printf and printf then prints all characters starting at that pointer until the end of the string. So that's why you get NING.

@ TheApex and sepp2k ,

Thank u.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.