Skip to content

Running C code in the terminal

I'm learning C, but I can't remember how to run my code, I compile it with tcc xyz.c and that's about it. I can't remember the command I used to run the code when I was learning cpp and I've searched on the internet for answers, but none of the responses answered my question. I'm spoiled by python.

0 points15 comments
Open on Reddit
About this post
Posted
Archived
Score
0 · 100% up
Kind
Text
ID
d2ddrl

Author

8
posts
34
comments
0
media
View profile

15 comments

. /binary_name

10 points

I don't think that was the command I was looking for, it was something similar, but I can't put my finger on it

-11 points

C is not interpreted. Once you compile it, you'll get a binary which you can execute - using ./binary_name as mentioned

12 points

What other command would you expect. When you compile C/C++ code it became an executable, which you can just run and you do it by typing the path to the binary file. If it is located in your current directory then you use ./ to tell your shell "use executable from current directory" and by adding binary_name you tell it to run your program, so you just use ./binary_name as u/A9-EE-78-6A-C8-9F has stated. This is the most basic method of all.

10 points

GCC will typically create the executable file a.out when the -o option is omitted, does tcc the same?

6 points

You should also be able to name the executable using the -o flag.

tcc xyz.c -o xyz

5 points

I remember not having to use -o, I might be mistaken, but I can't remember.

3 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.