Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Short Code 1

Why code 10 lines if you can code 1? Test your c++ short-cut knowledge here

Short Code 1

Postby antiRTFM on Tue Apr 22, 2008 1:27 am

Create the shortest program ever.

Rules;

One and only rule; It must be executable.

Hint: even if the program doesn't do anything really useful at all!

Before posting, please refer to the 'FAQ and Rules' section about posting code.


Good luck!
Last edited by antiRTFM on Wed Apr 23, 2008 4:59 am, edited 3 times in total.
User avatar
antiRTFM
Administrator
 
Posts: 456
Joined: Sun Apr 13, 2008 9:10 am

Postby Danielghofrani on Tue Apr 22, 2008 6:42 pm

Code: Select all

#include"stdafx.h"
#include<iostream>
int main() {
std :: cout << " Hi " ;
std :: cin.get() ;
return 0 ;
}
Danielghofrani
 
Posts: 3
Joined: Tue Apr 15, 2008 8:54 pm

Postby antiRTFM on Wed Apr 23, 2008 4:19 am

Danielghofrani:

1) its '/' not '\'
2) ok so far you have the shortest code, very well. We will need to wait for some competing coder to see if shorter exists. (hint: looks like you are doing some useful stuff in there. remember; we only need the program to be executable, not do anything useful)
3)
Before posting, please refer to the 'FAQ and Rules' section about posting code.
User avatar
antiRTFM
Administrator
 
Posts: 456
Joined: Sun Apr 13, 2008 9:10 am

reply

Postby Mike on Sun May 04, 2008 10:19 pm

Code: Select all
#include <iostream>
using namespace std;
string name;
cout<<"enter your name: ";
cin<<name;
cout<<"Wow your name"<<name<<" is really cool!";
cin.get();
}


XD
Mike
 
Posts: 1
Joined: Sun May 04, 2008 10:12 pm

Postby NOOB on Tue May 06, 2008 11:09 am

HERM tahts easy ;)

Code: Select all

#include"stdafx.h"
#include<iostream>
int main()
{
cin.get();
}
NOOB
 
Posts: 59
Joined: Tue May 06, 2008 11:04 am

Postby Rahl on Tue May 06, 2008 10:02 pm

Code: Select all
#include "stdafx.h"
int main(){
return 0;
}
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby NOOB on Wed May 07, 2008 7:57 am

O could we have a forum where we can post little projects and such we createt ?
So like our little text based battle system or such ?
please.
PS the videos are great.
Im german but i think yout english is ok :)
Last edited by NOOB on Sun May 11, 2008 5:34 am, edited 1 time in total.
NOOB
 
Posts: 59
Joined: Tue May 06, 2008 11:04 am

Postby antiRTFM on Sun May 11, 2008 1:07 am

NOOB:

The showcase section was just put up- at your request :)

anyway, the winner so far is Rahl!
NOOB- you did not bad by omitting "return 0;" because, though i didnt mention this in the video so as not to confuse anyone, the main() function is ok even without typing up "return 0;" explicitly. Unfortunately though, your program had an extra step in there- the waiting for some input...

And bearing in mind that #include "stdafx.h" isn't at all necessary according to standard c++, but rather its just a Microsoft Visual Studio thing, the best solution i can come up for this snippet contest is:
Code: Select all
int main(){}

User avatar
antiRTFM
Administrator
 
Posts: 456
Joined: Sun Apr 13, 2008 9:10 am

Postby Rahl on Sun May 11, 2008 9:35 pm

if you don't explicitly return something for the main function, is a return of 0 assumed?
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

Postby antiRTFM on Sun May 11, 2008 11:10 pm

Yes.

Quote from the standard c++ draft (3.6.1 5):

...If control reaches the end of main without
encountering a return statement, the effect is that of executing
return 0;
User avatar
antiRTFM
Administrator
 
Posts: 456
Joined: Sun Apr 13, 2008 9:10 am

Postby Rahl on Sun May 11, 2008 11:37 pm

Ok cool, thanks for clearing that up.
Rahl
 
Posts: 8
Joined: Tue May 06, 2008 9:58 pm

1 line program

Postby Argio on Wed Jun 25, 2008 8:50 pm

Code: Select all
include<iostream> using namespace std; int main(){ cout <<"HI!" <<endl;cin.get}
User avatar
Argio
 
Posts: 21
Joined: Fri Jun 20, 2008 5:04 am
Location: Utah. I am jewish.

Postby asib on Wed Jul 23, 2008 1:10 pm

You haven't put the space after the <<.
asib
 
Posts: 86
Joined: Tue Jul 22, 2008 9:15 pm

Postby Marss++ on Wed Jul 23, 2008 2:10 pm

I would say that the shortest program ever would be:

Code: Select all

int main(){}




It doesn't get any simpler then that. You don't need to include anything. You don't need to return anything. It doesn't even have to do anything. The challenge was make the shortest code ever. Never said it has to do something. So That's all there is to it.

Good job though guys.
I'm a 15 year old kid who has his heart set on Programming.

Came here hoping to help so if you have any questions just ask!
Marss++
 
Posts: 149
Joined: Fri Jul 18, 2008 3:20 pm

Postby C++ on Tue Aug 19, 2008 8:40 am

Marss++ wrote:I would say that the shortest program ever would be:

Code: Select all

int main(){}




It doesn't get any simpler then that. You don't need to include anything. You don't need to return anything. It doesn't even have to do anything. The challenge was make the shortest code ever. Never said it has to do something. So That's all there is to it.

Good job though guys.


That was already mentioned by antiRTFM :roll:

Oh and the smallest executable is one byte if you're not coding it in C++ and platform specific.

DOS backwards compatibility still allows for a simple x86 ret opcode. The program loader loads the return address to the start of the Program Segment Prefix structure on the stack. A simple 'ret' opcode will therefore actually run like a program but does nothing other than returning control to DOS.
C++
teh awesome
 
Posts: 217
Joined: Sun May 25, 2008 7:45 am

Next

Return to Short code

Who is online

Users browsing this forum: No registered users and 0 guests