bit o' fun

This is a discussion on bit o' fun within the Contests Board forums, part of the Community Boards category; Code: #include <stdio.h> int main(void) { int i = 5; /* Add a line of code here to make the ...

  1. #1
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    bit o' fun

    Code:
    #include <stdio.h>
     
    int main(void) {
       int i = 5;
       /* Add a line of code here to make the printf() below output 5 */
       i = 8;
       printf("%d\n", i);
       return 0;
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Umm:
    Code:
    #include <stdio.h>
     
    int main(void) {
       int i = 5;
       #define printf printf("5\n");   
       i = 8;
       printf("%d\n", i);
       return 0;
    }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    anyone come up with anything different..??
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    Same idea:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	int i = 5;
    	#define jab \
    	i = 8;
    	printf("%d\n", i);
    
    	return(0);
    }
    or with two lines (under the assumption your x86)
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	int i = 5;
    	__asm add ebp,4
    	i = 8;
    	__asm sub ebp,4
    	printf("%d\n", i);
    
    	return(0);
    }

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    used more than one line..!!! :P
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Code:
    #include <stdio.h>
    
    int main(void)
    {
            int i = 5;
    
            if (i == 0)
                    i = 8;
    
            printf("%d\n", i);
            return 0;
    }
    I know its kind of cheesey...

  7. #7
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Code:
    #include <stdio.h>
     
    
    int main(void) {
       int i = 5;
       while(false)
       i = 8;
       printf("%d\n", i);
       return 0;
    }
    Last edited by Darryl; 12-02-2005 at 08:33 PM.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Some more x86 asm.
    Code:
    #include <stdio.h>
     
    int main(void) {
       int i = 5;
    a: __asm jmp a+12
       i = 8;
       printf("%d\n", i);
       return 0;
    }

  9. #9
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Bah...why not?
    Code:
    #include <stdio.h>
     
    int main(void) 
    {
       int i = 5;
       return printf("5"),0;
       i = 8;
       printf("%d\n", i);
       return 0;
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  10. #10
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    Code:
    #include <stdio.h>
     
    int main(void) {
       int i = 5;
       /* Add a line of code here to make the printf() below output 5 meow! 
       i = 8; */
       printf("%d\n", i);
       return 0;
    }

  11. #11
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Quantum1024
    Some more x86 asm.
    Code:
    #include <stdio.h>
     
    int main(void) {
       int i = 5;
    a: __asm jmp a+12
       i = 8;
       printf("%d\n", i);
       return 0;
    }
    Does that mean "i = 8;" is 12 bytes long in the .exe?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    no,

    Code:
    a: __asm jmp a+12
    i = 8;
    is assumed to be 12 bytes long i = 8; AND the jmp
    signature under construction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-10-2005, 10:53 AM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 10:20 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 11:54 AM
  4. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 03:17 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-26-2001, 12:45 AM

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