CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: C_program

  1. #1
    Join Date
    Feb 2012
    Location
    INDIA
    Posts
    25

    C_program

    #include<stdio.h>

    void main()
    {

    char a = 'AB';

    printf("%c", a);
    }

    // In the above program why the output is 'B';

    Here we are assigning 'AB' to a char and there's no compiler error.
    TANUSHREE-AGRAWAL...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C_program

    Quote Originally Posted by Tanushreeagr View Post
    Code:
    #include<stdio.h>
    
    void main()
    {
    	char a  =  'AB';
    	printf("%c", a);
    }
    
    // In the above program why the output is 'B';
    Here we are assigning 'AB' to a char and there's no compiler error.
    First use Code tags!
    Second, try to avoid empty lines is such a short snippet.
    Third, what compiler are you using? My VC2010 shows the following warnings:
    Code:
    d:\2010 projects\...: warning C4305: 'initializing' : truncation from 'int' to 'char'
    d:\2010 projects\...: warning C4309: 'initializing' : truncation of constant value
    Is it clear now?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: C_program

    // In the above program why the output is 'B';
    Start with reading C++ Character Constants which 'AB' really is.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured