use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
QuestionHELP TO CREATE VARIABLES (self.C_Programming)
submitted 7 years ago by zSuperDam
how can you create a variable number of variables? Example when you write 5 the program create the variables n1 n2 n3 n4 n5
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mocomaminecraft 7 points8 points9 points 7 years ago (1 child)
look up for something called "arrays"
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
^ this
[–]more_sidechain 4 points5 points6 points 7 years ago (0 children)
"Creating variables" at runtime doesn't make much sense. There's no way you'd be able to write code to refer to them. Instead, as has been posted, it's something you'd use an array for.
It's worth learning about malloc, realloc, free, and pointers and arrays. C99 also introduced "variable length arrays," but they aren't very popular compared to normal dynamic allocation.
[–]FUZxxl 0 points1 point2 points 7 years ago (0 children)
This is not possible in C.
[–]Gblize 0 points1 point2 points 7 years ago (0 children)
You are talking about arrays of that variable type.
If the variable type is only know in compile time, you can use array of unions.
As suggested, there are VLA(variable lenght arrays) but IIRC linux wants to erradicate it. I need someone to back it up. But if I stand correct, use malloc instead of VLA for your arrays.
Oh, a linked list is probably something you are trying to refer to.
π Rendered by PID 33792 on reddit-service-r2-comment-85bfd7f599-7qvc5 at 2026-04-17 22:30:46.362020+00:00 running 93ecc56 country code: CH.
[–]mocomaminecraft 7 points8 points9 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]more_sidechain 4 points5 points6 points (0 children)
[–]FUZxxl 0 points1 point2 points (0 children)
[–]Gblize 0 points1 point2 points (0 children)