[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: senko-light.gif (58 KB, 220x123)
58 KB
58 KB GIF
>guy from discord offers to teach me coding
>he gives me some fundamentals of C++ and tasks me with writing a hello world
>write it and send it to him
>he just told me "fuck you" and blocked me
>>
File: 1692467899628.png (523 KB, 758x926)
523 KB
523 KB PNG
>>107975956
Post the Hello World?
>>
did you fuck up writing hello world or something? what the hell did you write
>>
>>107975963
>>107975964
Please explain what is wrong

#include <iostream>

using namespace std;

int main()
{
char char1 = 'H';
char char12 = 'e';
char char13 = 'l';
char char14 = 'l';
char char15 = 'o';
char char16 = ' ';
char char17 = 'w';
char char18 = 'o';
char char19 = 'r';
char char10 = 'l';
char a = 'd';
char b = '!';
int value = 0

std::cout << char1 << char12 << char13 << char14 << char15 << char16 << char17 << char18 << char19 << char10 << a << b << endl;
return 0;
}
>>
>>107975976
>Please explain what is wrong
Everything
>>
>>107975976
he was right to block you
>>
>>107975976
fuck you
>>
File: 1717715377813.gif (597 KB, 428x498)
597 KB
597 KB GIF
>>107975976
>Please explain what is wrong
You forgot a semicolon on the line where you set value to 0. You wrote:
int value = 0

When it should be
int value = 0;

If you make that change it will compile.
>>
>>107975976
This is some elaborate joke right?
>>
>>107975976
Based
>>
File: brackets.jpg (108 KB, 1920x1080)
108 KB
108 KB JPG
>>107975976
>not using K&R brackets
Found your problem.
>>
disgusting anime freaks
>>
>using #include instead of import
>using std::cout, instead of std::println
There’s your problem
>>
File: 1444177829383.jpg (33 KB, 453x500)
33 KB
33 KB JPG
>>107975976
Include me in the screencap
>>
File: 1536027295568.jpg (102 KB, 1036x1051)
102 KB
102 KB JPG
>>107976037
This is a maidposting site.
>>
>>107975976
Don't let them get you down, sweet cheeks. I've been looking for a ditz like you to be a live in maid/sexual relief outlet
>>
>>107976021
>elaborate
>>
File: 1758585171869656.png (156 KB, 614x738)
156 KB
156 KB PNG
>>107976020
>Please explain what is wrong
Here:
using namespace std;

You do not need this line.
>>
>>107975976
"Here’s some gentle, constructive feedback you can pass along—aimed at building confidence while nudging toward good habits

---

First: what they did right

This program shows curiosity and effort, and that matters a lot. Breaking the message into individual char variables demonstrates that they understand:

what a char is,

how characters are stored,

how std::cout chains outputs together.

That’s not nothing. That’s real learning

---

A few small fixes (very normal beginner stuff)

There are two tiny errors that would stop the program from compiling:

1. Missing semicolon

int value = 0

Needs:

int value = 0;

2. endl needs the std:: prefix Since the code uses std::cout, it should also use:

std::endl

(or rely fully on using namespace std;, but consistency helps early on).

---

Things that could be improved (without changing the idea)

Variable names like char12, char13, etc. technically work, but they’re hard to read. Names like h, e, l1, l2 would already be clearer.

int value = 0; is never used. That’s harmless, but removing unused variables keeps code clean.

Mixing using namespace std; and std::cout is a bit inconsistent. Pick one style and stick to it.

---

A simpler (but equally valid) next step

Once they’re comfortable, this is how most C++ programs say hello:

#include <iostream>

int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}

This doesn’t mean the original approach was wrong—it just means they’re ready to move up a rung on the ladder

---

Programming isn’t about typing the shortest solution—it’s about understanding what the computer is doing. This program shows experimentation and curiosity, which is exactly how programmers are made.
>>
>>107976112
oops meant for >>107975976
>>
>>107975976
Here is fixed code Sir,
#include <iostream>
#include <cstdlib>

using namespace std;

class CharFactory {
public:
int allocateData(size_t number_of_characters) {
this->data = (char*)malloc(sizeof(char) * number_of_characters + 1);
return number_of_characters;
}
char addCharacterToData(char character_to_add, int position) {
this->data[position] = character_to_add;
return character_to_add;
}
char* getData() const {
return this->data;
}
private:
char* data;
};

int main()
{
char char1, char12, char13, char14, char15, char16, char17, char18, char19, char10, a, b;
CharFactory character_factory_for_print_output;
character_factory_for_print_output.allocateData(std::size("Hello world!"));
char1 = 'H';
char12 = 'e';
char13 = 'l';
char14 = 'l';
char15 = 'o';
char16 = ' ';
char17 = 'w';
char18 = 'o';
char19 = 'r';
char10 = 'l';
a = 'd';
b = '!';
int value = -1;
character_factory_for_print_output.addCharacterToData(char1, ++value);
character_factory_for_print_output.addCharacterToData(char12, ++value);
character_factory_for_print_output.addCharacterToData(char13, ++value);
character_factory_for_print_output.addCharacterToData(char14, ++value);
character_factory_for_print_output.addCharacterToData(char15, ++value);
character_factory_for_print_output.addCharacterToData(char16, ++value);
character_factory_for_print_output.addCharacterToData(char17, ++value);
character_factory_for_print_output.addCharacterToData(char18, ++value);
character_factory_for_print_output.addCharacterToData(char19, ++value);
character_factory_for_print_output.addCharacterToData(char10, ++value);
character_factory_for_print_output.addCharacterToData(a, ++value);
character_factory_for_print_output.addCharacterToData(b, ++value);

std::cout << character_factory_for_print_output.getData() << std::endl;
return value - std::size("Hello world!");
}
>>
Made me remember when I was learning Python and wanted to somehow make a "list" of variables. After some research I did something along the lines of
for n in range(...):
value = ...
exec("var%d = %d"% (n, value))
>>
>>107976119
>it's not X, it's Y
God I hate chatbot speak so much it's unreal
>>
>>107976083
iktf
>>
>>107975976
put me in the screencap
>>
File: 1587347161774.jpg (43 KB, 379x379)
43 KB
43 KB JPG
>>107975976
>>
File: 6qd9zf2g.jpg (11 KB, 400x321)
11 KB
11 KB JPG
>>107975956
Fuck you
>>
File: 1747614541806093.png (47 KB, 698x658)
47 KB
47 KB PNG
>>107975976
>discord groomer thought he caught an impressionable young boy but he ended up getting an experienced troll
>>
>>107975976
Nothing anon. You are just too based for this world
>>
File: he laughed.gif (2.64 MB, 506x360)
2.64 MB
2.64 MB GIF
>>107975976
That's beautiful anon.
>>
File: 1755159414125058.gif (370 KB, 535x480)
370 KB
370 KB GIF
>>107975976
>>
>>107978020
I was very disappointed in that novel because the sister was NBR.
>>
File: 1769464693747.jpg (33 KB, 732x554)
33 KB
33 KB JPG
>>107975976
bro what the hell is this
>>
File: 1739293353461369.jpg (102 KB, 1160x1449)
102 KB
102 KB JPG
>>107975976
>>
>>107975976
Yandev finish your fucking game
>>
>>107976069
>This is a maidposting site.
QRD?
>>
>>107975976
based retard
>>
>>107978079
Never seen assembly paradigm?
People take it for granted but "hello world", being processed as a single string datastructure, isn't the natural state of computation at the instruction level.
>Values aren't free
>The trees, memory stacks and addresses gotta be littered with eax and cmp instructions
>BASIC aka BASHIT is NOT my programming language. it is made by a jew and probably gommunist too :DDDD.
>JMP and RET not jump and return ok. Praise clock cycles.
>>
>>107975956
God I wish I had a dollar for every Hello World I did in various languages because /g reckoned it was the next big thing.

Away from /g world, what will pay your bills is a Hello World in .bat/.sh/ps. Most paid programming work is maintaining old shit that is out of support and mundane stuff like VBA in Excel. Don't take career advice off Anons - if they had a job they wouldn't be on this shithole (I am retired)
>>
File: zinsser.jpg (166 KB, 727x957)
166 KB
166 KB JPG
>>107975976
Fake and gay. Put me in the screencap anyways.
>>
>>107979033
I'd slap you if you did this in Assembly, too. Just write your string somewhere as hard-coded data and load a pointer to it rather than spending a whole bunch of instructions loading the characters into a buffer one by one.

(There are niche cases where you do push a hard-coded string onto the stack through direct instructions, but in those cases you do it in segments of 4 bytes or whatever is conventional for an integer on your architecture, not one byte at a time.)
>>
>>107979033
You have never written assembly. Or written it well.

I don't know how the << operator in C++ works, but you don't fucking allocate characters like that on the stack, discretely. And even if you have to, you do it in reverse if the stack on your machine grows down, and then pass it to the output subroutine as one string. The only exception is something primitive like the JSR $FFD2 on the C64, in which case you still do not fucking allocate the string on stack, you just fucking load and pass it from the segament where your program loads it.
>>
>>107979140
>>107979309
>I don't know how the << operator in C++ works
It's a stream operator. It's meant to push into the "stream" one memory unit at a time through a pipe/some shard memory space
>>107979140
8-bit architectures are perfectly valid forms of computation.
>>
>>107979385
>It's a stream operator. It's meant to push into the "stream" one memory unit at a time through a pipe/some shard memory space
I see.
>8-bit architectures are perfectly valid forms of computation.
As I said in the last post with my C64 $FFD2 kernal(that's how the the ROM name is spelled) subroutine example, you still would never do the string allocation in that way.
>>
>>107975976
You were supposed to use a for loop. Rookie mistake.
>>
>>107976165
I don't know how to read this, but that's a fork bomb.
>>
>discord
>c++
You'd have a better experience asking a boomer for Pascal books
>>
>>107975956
>>107975976
This didn't happen, you idiots...
>>
>>107975976
You motherfucker
>>
File: 1768719954818296.jpg (208 KB, 784x1168)
208 KB
208 KB JPG
>>107976069
Wrong, this is frog territory.
>>
>c++
Your first mistake, learn rust fag.
>>
Already good enough to work on windows
>>
>>107975976
Looks Blazingly Fastᵀᴹ
>>
>>107975976
Historic retardism
>>
>>107975976
Epic
>>
>>107975976
The problem is that char13, char14 and char10 are the same value so you could optimise by turning these 3 variables into one. This would make your program execute faster.
>>
>>107976112
We all know it needs to be
>using namespace studio;
>>
>>107980922
This, there's no way for anyone to be sure whether or not OP's program contains memory errors without rewriting it in Rust 1.96.0.
>>
>>107975976
Imagine trying to learn C++
>so this << symbol means... send data? Or something?
>let's try to google it
>it's actually the "left shift" operator, I wonder what that means? But it's "overloaded"
>I guess it's shifting my text to the left towards the std::cout
>>
>>107975976
>Char prefix variable names sorted in lexicographical order
>12 1 byte char variables and one 4 byte int creates 16 byte static allocation with perfect alignment
>Ending allocation with 0 for safety
This... This is a one in one million coder...
We found him
>>
File: pepe_(laugh).png (21 KB, 125x121)
21 KB
21 KB PNG
>>107975976
>>
>>107982808
100% chance the guy wrote seL4 and just decided to drop by and give us a laugh
>>
>>107976165
Anon, you allocated enough memory for the null terminator, but you didn't initialize it. UB.
>>
>>107980286
>>107976069
wrong board
>>>/lgbt/
>>
>>107975976
you should apply to microsoft
>>
File: 1583897837682.png (950 KB, 1112x832)
950 KB
950 KB PNG
>>107978632
On this site, it is customary to attach an image of a maid to all your posts when you don't need the image field for anything else.

This is colloquially know as maidposting.

>>107983242
The maids on /lgbt/ don't care about computers, except camo maid and I haven't seen her in years.
>>
>>107976702
You're looking for one too?
>>
File: IMG_7344.jpg (3.99 MB, 2480x3894)
3.99 MB
3.99 MB JPG
>>107983266
kys
/g/ is a megumin/lolicon board
>>
File: 1750152737412765.jpg (1.01 MB, 2100x3228)
1.01 MB
1.01 MB JPG
>>107983333
can't argue with those quads
>>
>>107983333
>not waiting until marriage to have passionate sex with dfc megumin in the missionary position for the purpose of procreation
Shameful
>>
>>107975976
Good job triggering all the jeets
>>
>>107983326
always
>>
Based senko
>>
>>107984880
Quadegumi
>>
>>107975976
You should post that on some other websites for AI to scrape.
It would be great to see this as a AI summary.
>>
>>107983226
there is a decent enough chance the memory there will be 0 anyway so its ok if it crashes the user can just rerun the program and try again
>>
>>107985874
Do that on Monwednesday
>>
>>107975976
Based
>>
>>107975976
Lmao
>>
>>107975976
It isn't assembly lil bro
>>
Forced cringe joke, mods please delete this thread
>>
>>107976596
ugh, I have to use SAS sometimes at work and this is how it does arrays
>>
>>107975976
Are you trying to be funny and cute?
>>
>>107975976
Can imagine the jeet got mad at this... lol.
>>
File: 1754280220170509.jpg (96 KB, 827x800)
96 KB
96 KB JPG
>>107975976
>>
File: file.png (77 KB, 725x698)
77 KB
77 KB PNG
>>107976165
I asked Claude Opus 4.5 to make a code review and here's what it suggested me:
#include <iostream>
#include <cstdlib>
#include <cstddef>

using namespace std;

class CharFactory {
public:
int allocateData(size_t number_of_characters) {
this->data = (char*)malloc(sizeof(char) * (number_of_characters + 1));
return number_of_characters;
}

char addCharacterToData(char character_to_add, int position) {
this->data[position] = character_to_add;
return character_to_add;
}

char* getData() const {
return this->data;
}

~CharFactory() {
if (this->data) {
free(this->data);
this->data = nullptr;
}
}

private:
char* data = nullptr;
};

int main() {
char char1, char12, char13, char14, char15, char16, char17, char18, char19, char10, a, b;
CharFactory character_factory_for_print_output;
size_t len = std::size("Hello world!") - 1;
character_factory_for_print_output.allocateData(len);
char1 = 'H';
char12 = 'e';
char13 = 'l';
char14 = 'l';
char15 = 'o';
char16 = ' ';
char17 = 'w';
char18 = 'o';
char19 = 'r';
char10 = 'l';
a = 'd';
b = '!';
int value = -1;
character_factory_for_print_output.addCharacterToData(char1, ++value);
character_factory_for_print_output.addCharacterToData(char12, ++value);
character_factory_for_print_output.addCharacterToData(char13, ++value);
character_factory_for_print_output.addCharacterToData(char14, ++value);
character_factory_for_print_output.addCharacterToData(char15, ++value);
// chart16 to char18 lol
character_factory_for_print_output.addCharacterToData(a, ++value);
character_factory_for_print_output.addCharacterToData(b, ++value);
character_factory_for_print_output.getData()[value + 1] = '\0';

std::cout << character_factory_for_print_output.getData() << std::endl;
return 0;
}

>>
>>107975956
Just ask an AI to teach you to code.
>>
>>107975976
You forgot a semicolon after int value = 0
>>
>>107975956
>anime image reaction
>he just told me "fuck you" and blocked me

Gee, how often this happen to you?
>>
>>107976119
>Names like h, e, l1, l2 would already be clearer.
LLMs come up with some bangers
>>
>>107975976
Kek thanks for the laugh
>>
>>107975976
8/8 b8
>>
>>107975976
in OCaml this is just
open Out_channel
open Printf
let (<<) out c = output_char out c; out
let endl = '\n'
let let1 = 'H'
let let12 = 'e'
let let13 = 'l'
let let14 = 'l'
let let15 = 'o'
let let16 = ' '
let let17 = 'w'
let let18 = 'o'
let let19 = 'r'
let let10 = 'l'
let a = 'd'
let b = '!'
let value = 0;;
stdout << let1 << let12 << let13 << let14 << let15 << let16 << let17 << let18 << let19 << let10 << a << b << endl
>>
File: 1766862344508938.gif (172 KB, 220x221)
172 KB
172 KB GIF
cute thread /g/
>>
>>107975976
fuck you.
>>
>>107975976
I know this is fake, but it legitimately made me laugh.
>>
File: GpJ-vbpW4AAaXLA.jpg (53 KB, 405x720)
53 KB
53 KB JPG
>>107975976
Respect



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.