Thread: Basic C++ program doubt.

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    1

    Basic C++ program doubt.

    Hi Guys, I have just started learning C++. I was writing a program in which i didn't get the desired output.
    I am posting my Code and the output i got.

    Code-
    #include<stdio.h>
    #include<conio.h>

    int main()
    {
    char college='tum';
    printf("Hi this is Nitin studying in %c",college);
    getch();
    return 0;
    }

    Output-
    Hi this is Nitin studying in m

    My doubt is why isn't the compiler displaying tum?

    It will be great if you point out the error and let me know the correct solution.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Try...

    Code:
    char college[]="tum";
    ...and use %s instead of %c. Also, I'd recommend getting rid of conio.h and using getchar() from stdio.h instead.
    Last edited by freddie; 01-19-2016 at 06:00 AM.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Please use code tags when posting code.

    This looks like C. Where are you getting this "C++" learning material from?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Matticus View Post
    Where are you getting this "C++" learning material from?
    Probably from the "Turbo C++" name on the build environment.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic doubt
    By pshirishreddy in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2009, 11:00 AM
  2. Basic doubt in C structure
    By cbalu in forum Linux Programming
    Replies: 2
    Last Post: 08-17-2009, 11:03 AM
  3. basic doubt
    By vikranth in forum C Programming
    Replies: 7
    Last Post: 10-30-2007, 11:21 AM
  4. basic doubt
    By sincere_cute in forum C Programming
    Replies: 2
    Last Post: 06-20-2007, 03:33 AM
  5. [B]a basic doubt !![/B]
    By samirself in forum C Programming
    Replies: 6
    Last Post: 04-30-2005, 01:39 PM