Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program ?

#include <stdio.h>
#include <string.h>

int main()
{
    printf("%d\n", strlen("123456"));
    return 0;
}

 

  • A.6
  • B.12
  • C.7
  • D.2

Answer: A

Correct answer: 6

strlen counts the characters before the terminating null. "123456" holds six digit characters - their being digits is irrelevant - so the answer is 6. sizeof on the same literal would give 7.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.