Code Golf: Code Golf: Difference between revisions

→‎{{header|C}}: Programs replaced by shorter ones.
m (→‎{{header|Perl}}: Save one character)
(→‎{{header|C}}: Programs replaced by shorter ones.)
Line 130:
=={{header|C}}==
 
The following answers assume compilation using gcc 11.3.0 on ubuntu 22.04, without using any special options and ignoring the warnings that:.
 
The shortest possible program (2826 bytes) to print the required string is:
1. The default return type of 'main' is 'int'; and
<syntaxhighlight lang="c">main(){printfputs("Code Golf");}</syntaxhighlight>
 
The size of the executable needed to run this is 15,968960 bytes.
2. 'printf' is being implicitly declared (i.e. no explicit #include <stdio.h>).
 
If the program itself cannot contain string or character literals, then the shortest program I've been able to come up with (8248 bytes) is:
The shortest possible program (28 bytes) to print the required string is:
<syntaxhighlight lang="c">main(){printf("Code Golf");}</syntaxhighlight>
 
<syntaxhighlight lang="c">main(){int ca[]={370x65646f43,90x6c6f4720,2,3,70,33,9,10,0102};formain(int i=0;i<9;++i)printf{puts("%c",c[i]^102a);}</syntaxhighlight>
The size of the executable needed to run this is 15,968 bytes.
 
The size of the executable needed is now 1615,016992 bytes.
If the program itself cannot contain string or character literals, then the shortest program I've been able to come up with (82 bytes) is:
 
<syntaxhighlight lang="c">main(){int c[]={37,9,2,3,70,33,9,10,0};for(int i=0;i<9;++i)printf("%c",c[i]^102);}</syntaxhighlight>
 
The size of the executable needed is now 16,016 bytes.
 
Output in both cases:
4

edits