Knowee
Questions
Features
Study Tools

Select the correct answerPredict the output of below given code.#include <stdio.h>int Function(char *S1){ char *S2 = S1; while(*++S1); return (S1-S2);} int main(){ char *Str = "CodeTantra Coding Castle"; printf("%d", Function(Str)); return 0;}Options2524Segmentation Fault26Garbage Value

Question

Select the correct answerPredict the output of below given code.#include <stdio.h>int Function(char *S1){ char S2 = S1; while(++S1); return (S1-S2);} int main(){ char *Str = "CodeTantra Coding Castle"; printf("%d", Function(Str)); return 0;}Options2524Segmentation Fault26Garbage Value

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is 25.

Here's the step by step explanation:

  1. The main function calls the Function with a string "CodeTantra Coding Castle" which has 25 characters including the space.

  2. In the Function, a pointer S2 is initialized to the start of the string S1.

  3. The while loop increments the pointer S1 until it points to the null character at the end of the string.

  4. After the loop, S1 points to the end of the string and S2 points to the start of the string.

  5. The difference between the two pointers (S1-S2) gives the length of the string, which is 25.

So, the output of the program will be 25.

This problem has been solved

Similar Questions

Select the correct answerWhat will be the output of the following Python code?>>>ct1="codetantra">>>ct1[:3]>>>Optionsdecododetacodetantra

Select the correct answerWhat will be the output of the following Python code snippet if x=1?x<<2Options1248

Select the correct answerWhat will be the output of the following Python code snippet?c = 2for t in range(c):  c -= 2  print (c)Options0-20error01234 …

Select the correct answerWhat will be the output of the following Python code snippet?ct = 'code'for i in range(len(ct)):   i.upper()print (ct)Optionsc o d eerrornone of the mentioned0 1 2 3

Select the correct answerWhat will be the output of the following Python code snippet?print('Hola Amigos'.istitle())OptionsFalseErrorNoneTrue

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.