CrazyEngineers
  • Gaurav
    Gaurav

    MemberSep 19, 2013

    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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • nareshkumar6539

    MemberSep 19, 2013

    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<stdio.h>

    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
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberSep 19, 2013

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorSep 19, 2013

    Note: Please wrap your code in
    [code]

    .....

    [/code]

    tags so that it looks nice and properly formatted 😀

    Example:

    #include<stdio.h>
    
    int main()
    {
    
    printf("%d",printf("computer"));
    
    return (0);
    
    }
    
    Are you sure? This action cannot be undone.
    Cancel
  • Gaurav Deshmukh

    MemberSep 20, 2013

    try out for this guys....
    give the o/p of following program....

    and also write some tricky program as reply😀..

    #include<stdio.h>
    
    int main()
    {
      int i;
    
      for(i=0;i<5;i++)
        {
          int i = 10;
       
            printf("%d",i);
        }
      return (0);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberSep 20, 2013

    Well i' value will be printed 5 times.
    1010101010(as no space and newline demand in your program).
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberSep 20, 2013

    check the output of this code :


    #include<stdio.h>
    
    int main()
    {
      int i;
    
      for(i=0;i<5;i++);
        {
          int i = 10;
     
            printf("%d",i);
        }
      return (0);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Gaurav Deshmukh

    MemberSep 20, 2013

    Rite dear😀
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberSep 20, 2013

    I think "the CE coding challenge" thread is kinda same! why to have two of such threads? 😨
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberSep 20, 2013

    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<stdio.h>
    int main() {
    int i=1;
    for(i=1,j=5;i<5;i++,j--)
    {
      printf("%c  %c\n",i,j);    
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberSep 20, 2013

    @#-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.
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberSep 20, 2013

    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 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberSep 20, 2013

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberSep 20, 2013

    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.
    😀
    Are you sure? This action cannot be undone.
    Cancel
  • Ashutosh Tripathy

    MemberSep 26, 2015

    Can any one show me a better kind of tricky c program?
    Are you sure? This action cannot be undone.
    Cancel
  • krishna vamsi ChinnapaReddy

    MemberFeb 29, 2016

    v
    vr
    vrs
    vrse
    vrsec
    vrse
    vrs
    vr
    v
    Are you sure? This action cannot be undone.
    Cancel
  • sunilmit

    MemberMay 19, 2016

    Shailaja Tiwari
    check the output of this code :


    #include<stdio.h>
    
    int main()
    {
    static   int i;
    
      for(i=0;i<5;i++);
        {
          static int i = 10;
    
            printf("%d",i);
        }
      return (0);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • nikhila goli

    MemberMay 21, 2016

    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
    Are you sure? This action cannot be undone.
    Cancel
  • Anshul Jain

    MemberSep 2, 2018

    #-Link-Snipped-# 

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

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


    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register