Tricky C Programs Collection

hey guys ,
just write any tricy c code ...
as the game everyone will answer it ..
ok 1st my turn,,,

what will be the output of following code

#include

int main()
{

printf("%d",printf("computer"));

return (0);

}

Replies

  • nareshkumar6539
    nareshkumar6539
    Gaurav v. Deshmukh
    hey guys ,
    just write any tricy c code ...
    as the game everyone will answer it ..
    ok 1st my turn,,,

    what will be the output of following code

    #include

    int main()
    {

    printf("%d",printf("computer"));

    return (0);

    }
    Answer:computer8
    First it will print computer and printf() is a predefined function it will return how many characters printed In this case it is printing 8 characters it will return 8.

    OutPut :computer8
  • Shailaja Tiwari
    Shailaja Tiwari
    answer is computer8 as printf will return the number charcters enclosed within it's function parentheses and one clue is the format specifier %d that is usually used with numbers.
  • Kaustubh Katdare
    Kaustubh Katdare
    Note: Please wrap your code in
    [code]

    .....

    [/code]

    tags so that it looks nice and properly formatted 😀

    Example:

    #include
    
    int main()
    {
    
    printf("%d",printf("computer"));
    
    return (0);
    
    }
    
  • Gaurav Deshmukh
    Gaurav Deshmukh
    try out for this guys....
    give the o/p of following program....

    and also write some tricky program as reply😀..

    #include
    
    int main()
    {
      int i;
    
      for(i=0;i<5;i++)
        {
          int i = 10;
       
            printf("%d",i);
        }
      return (0);
    }
  • Shailaja Tiwari
    Shailaja Tiwari
    Well i' value will be printed 5 times.
    1010101010(as no space and newline demand in your program).
  • Shailaja Tiwari
    Shailaja Tiwari
    check the output of this code :


    #include
    
    int main()
    {
      int i;
    
      for(i=0;i<5;i++);
        {
          int i = 10;
     
            printf("%d",i);
        }
      return (0);
    }
  • Gaurav Deshmukh
    Gaurav Deshmukh
    Rite dear😀
  • Vishal Sharma
    Vishal Sharma
    I think "the CE coding challenge" thread is kinda same! why to have two of such threads? 😨
  • rahul69
    rahul69
    Vishal0203
    I think "the CE coding challenge" thread is kinda same! why to have two of such threads? 😨
    I think this thread is to give output of tricky codes, whereas in other one we have to give solutions for problems.
    Here is another one:
    Give the output of the following program:
    #include
    int main() {
    int i=1;
    for(i=1,j=5;i<5;i++,j--)
    {
      printf("%c  %c\n",i,j);    
    }
    }
  • Shailaja Tiwari
    Shailaja Tiwari
    @#-Link-Snipped-# I guess multiple declaration of i=1 won't be allowed.

    and %c (meant for characters) is not valid format specifier for printing integers.
    So I guess the above program will give a wierd o/p.
  • rahul69
    rahul69
    Shailaja Tiwari
    @#-Link-Snipped-# I guess multiple declaration of i=1 won't be allowed.
    Actually I used C++ compiler so that multiple declaration didn't gave error (but will give error in C compiler)😁. So it's edited 👍.
    Shailaja Tiwari
    @#-Link-Snipped-#
    and %c (meant for characters) is not valid format specifier for printing integers.
    So I guess the above program will give a wierd o/p.
    And u have to guess that weird o/p 😀
  • Shailaja Tiwari
    Shailaja Tiwari
    a number printed in %c format specifier would get converted to it's equivalent character in terms of ascii codes.So it might be a sort of symbols.

    Correct me if i'm wrong.
  • rahul69
    rahul69
    Shailaja Tiwari
    a number printed in %c format specifier would get converted to it's equivalent character in terms of ascii codes.So it might be a sort of symbols.

    Correct me if i'm wrong.
    Yes u are right. It will print different characters like smile face, diamonds, hearts etc.
    😀
  • Ashutosh Tripathy
    Ashutosh Tripathy
    Can any one show me a better kind of tricky c program?
  • krishna vamsi ChinnapaReddy
    krishna vamsi ChinnapaReddy
    v
    vr
    vrs
    vrse
    vrsec
    vrse
    vrs
    vr
    v
  • sunilmit
    sunilmit
    Shailaja Tiwari
    check the output of this code :


    #include
    
    int main()
    {
    static   int i;
    
      for(i=0;i<5;i++);
        {
          static int i = 10;
    
            printf("%d",i);
        }
      return (0);
    }
  • nikhila goli
    nikhila goli
    nareshkumar6539
    Answer:computer8
    First it will print computer and printf() is a predefined function it will return how many characters printed In this case it is printing 8 characters it will return 8.

    OutPut :computer8
  • Anshul Jain
    Anshul Jain

    #-Link-Snipped-# 

    I think that i'll give a compile time error because the variable j is not declared

    #include int main(){ int i=1; for(i=1,j=5;i<5;i++,j--) { printf("%c %c\n",i,j); } }


You are reading an archived discussion.

Related Posts

By shifting the solar panel inside the aerodynamically designed shell, Cambridge University students have upped the ante on the October’s World Solar Challenge, a gruelling four-day-long, 3,000km race across the...
MIT ha scome up with Hyperform that makes 3D printing of large bojects literally a snap. This radically different approach can dramatically change 3D printing nad herald a major advance....
The Telegraph of UK has published this interesting gallery of pictures showing the 150 years history of the London Tube Railway. Amazing engineering of yester years. https://www.telegraph.co.uk/travel/p...ears-of-London-Underground.html?frame=2447187 (Originally posted by...
Quote: Multiple entries are accepted, but each entrant can only win one prize. Contest is open to entries from US, Canada [excluding Quebec], UK, China, Belgium, the Netherlands, Australia, Colombia,...
We've been receiving serious concerns over the news items being shared for the sake of creating new threads and accumulating points for CEoM contest. We need to address this concern....