Reputation: 1719
I'm writing this code to use sizeof() function with a char array of 7 elements, I thought that the output should be 8 because of the 7 elements PLUS the terminator of the array but surprised that the output was 5?? HOW COME?
#include<stdio.h>
int main(void)
{
char str[]="S\065AB";
printf("\n%d",sizeof(str));
return 0;
}
Upvotes: 0
Views: 155
Reputation: 145919
Use:
char str[]="S\\065AB";
instead of
char str[]="S\065AB";
\065
is a C escape sequence.
Upvotes: 5
Reputation: 477680
\065
is a single character, represented as an octal escape sequence.
Upvotes: 6