Multiple choice technology programming languages

char* riteshFunc (char *ptr) { ptr += 3; return (ptr); } int main() { char *x, *y; x = "HELLO"; y = riteshFunc(x); printf ("y = %s \n", y); return 0; } What will print when the sample code above is executed?

  1. HELLO

  2. ELLO

  3. LLO

  4. LO

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Pointer arithmetic moves the pointer 3 characters forward from H-E-L-L-O, so it points to L-L-O. The printf outputs from that position, printing LO. Options A, B, and C are incorrect pointer offsets.

AI explanation

x points to the string literal "HELLO". Passing it to riteshFunc adds 3 to the pointer value, moving it forward 3 characters in the same underlying array (pointer arithmetic doesn't copy or alter the string). Index 0 is 'H', so index 3 is 'L', meaning the returned pointer now starts at "LO" and that's what gets printed. Options like "ELLO" or "LLO" would correspond to shifting by only 1 or 2 characters.