Thread: plz explain......

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    4

    Exclamation plz explain......

    Code:
    #include<stdio.h>
    int main()
    {
     char a; //local variable 
     int i; //local variable
     printf("%d",i);
     printf("%c",a);
     return ;
    }
    i just wanna know that the concept states that only static and global variables are initialized to zero by default..............then how come in this case if I output "i" or even "a" using the printf command it is displaying the output as zero when both are local variables........??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you're seeing when you print a, that means a must have the value 48, since that's what the character '0' is.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Coincidence. Here's my output (I inserted a new line to separate the numbers:
    Code:
    2856256
    That blank second line happens to be a zero, but the int is clearly uninitialized.

    As a side note, you declare main to return an int, so it needs to return an int. Make that last line "return 0;".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plz explain these 2 lines
    By ankit8946 in forum C Programming
    Replies: 1
    Last Post: 10-31-2009, 09:39 AM
  2. plz explain the output of the program.
    By raj_ksrt in forum C++ Programming
    Replies: 2
    Last Post: 05-26-2008, 03:43 AM
  3. plz explain a small function
    By samirself in forum C Programming
    Replies: 4
    Last Post: 11-11-2004, 10:14 AM
  4. plz explain
    By polonyman in forum C++ Programming
    Replies: 1
    Last Post: 09-12-2004, 04:15 AM
  5. Can someone explain this to me plz...
    By CAP in forum C Programming
    Replies: 3
    Last Post: 07-23-2002, 01:30 PM