CrazyEngineers
  • #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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorOct 8, 2011

    Thread moved from Introductions section to Computer Science & IT engineering section.
    Are you sure? This action cannot be undone.
    Cancel
  • Pensu

    MemberOct 8, 2011

    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???
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 8, 2011

    diwana.nanda
    #include<stdio.h>
    #include<string.h>
    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'
    Are you sure? This action cannot be undone.
    Cancel
  • diwana.nanda

    MemberOct 21, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register