Cannot able to understand the output

This is a discussion on Cannot able to understand the output within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> void main() { printf("%%%%\n"); } output: %% Why the output is '%%'?? Why not '%%%%'? If I replace ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    Bangalore,INDIA
    Posts
    14

    Unhappy Cannot able to understand the output

    Code:
    #include<stdio.h>
    void main()
    {
     printf("%%%%\n");
    }
    output:
    %%

    Why the output is '%%'??
    Why not '%%%%'?
    If I replace '%' with '$', then output is '$$$$'. Why?

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Bangalore,INDIA
    Posts
    14
    I am using Turbo C 4.5 on Windows 7 platform

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    '%' is a format specifier. It has special meaning. Just like '\' is expecting more characters afterwards but if you want '\' output then you have to use '\\'.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by raj.knd View Post
    I am using Turbo C 4.5 on Windows 7 platform
    My condolences...

    (You really should think about a better compiler, something like ... Pelles C)

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    Bangalore,INDIA
    Posts
    14
    Yes. I made the changes and got the answer. Thank you.

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    Bangalore,INDIA
    Posts
    14
    Thank you Tater. I will try to get that one.

  7. #7
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    107
    you should also know that the return type of main is int not void.and you can't get away with void main() in up-to-date compilers like pelles c. read this
    Cprogramming.com FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])

  8. #8
    Registered User phanideepak007's Avatar
    Join Date
    Nov 2011
    Location
    Earth
    Posts
    7
    the printf() function uses the % symbol to identify the conversion specifications, there is a slight problem if you want to print the % sign itself. If you simply use a lone % sign, the compiler thinks you have bungled a conversion specification. The way out is simple—just use two % symbols, as shown here:


    pc = 2*6; printf("Only %d%% of Sally's gribbles were edible.\n", pc);
    The following output would result:



    Only 12% of Sally's gribbles were edible.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 09:26 AM
  2. i cant understand why i get such an output??
    By transgalactic2 in forum C Programming
    Replies: 5
    Last Post: 10-16-2008, 07:06 AM
  3. tricky output problem, dont understand
    By panfilero in forum C Programming
    Replies: 6
    Last Post: 11-12-2005, 12:30 AM
  4. cannot understand this output - atoi
    By aldajlo in forum C Programming
    Replies: 11
    Last Post: 10-02-2004, 12:48 PM
  5. Replies: 3
    Last Post: 02-19-2003, 08:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21