a crazy question for c programmers

#include
#include
void main()
{
char name[5]="sajan";

printf("%s",name);

getch();

}

output:

sajan with a grbage value...................

que1:-where it store the null character if size is equal to the characters entered?

que2:-if we take even size nd same number of character then it wil genrate error in c, bt not in c++.why this heppens...

explain me logic plzzzzzz...................\

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    Thread moved from Introductions section to Computer Science & IT engineering section.
  • Pensu
    Pensu
    For the first one, u have answer in question itself, there is no place for null character. So, when compiler starts printing the string and it doesnt find any null character, it doesnt know where to stop, ergo garbage value.
    And i didnt get the second question, what error r u getting in C???
  • Rupam Das
    Rupam Das
    diwana.nanda
    #include
    #include
    void main()
    {
    char name[5]="sajan";

    printf("%s",name);

    getch();

    }

    output:

    sajan with a grbage value...................

    que1:-where it store the null character if size is equal to the characters entered?

    que2:-if we take even size nd same number of character then it wil genrate error in c, bt not in c++.why this heppens...

    explain me logic plzzzzzz...................\
    have you tried this c program in unix? my friend it is not c or c++, it is compiler. turbo c compiler does not consider appending a null once you press enter after scanf. so to avoid this, they have given the facility of 'gets'
  • diwana.nanda
    diwana.nanda
    guyz my second que is
    if i ll take thesize of array in even no. in c and c++ it will not generate error. but if i take size in odd numbers it will genrate error in c++ but not in c compiler..................
    this was the main question.

You are reading an archived discussion.

Related Posts

Hello guy's Anyone have idea how to work with ajax in java ? I am using tomcat 7.0.If possible please provide a small tutorial or provide any link where i...
project topic: DESIGN AND FABRICATION OF A PORTABLE WORK PLATFORM ELEVATED BY TWO HYDRAULIC CYLINDERS ( SCISSOR LINKAGES) please gurus help me,i need to make it as early as possible...
Hello CEans, As human beings we all make mistakes. But as ignorance blinds us or as our pride is too high, we fail to pardon ourselves for what has happened....
If somebody is interested to know how CE is Grown: Here is the statistics, collected from various algorithms of Mine. If the data is objectionable , I am open to...
From which institute I can get postal material to prepare for gate2012 metallurgical engineering? preferably in south indian or else whole of india..... If not some online materials....