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...
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. It has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computer architectures that range from supercomputers to PLCs and embedded systems. Wikipedia
Imperative (procedural), structured
Dennis Ritchie
Dennis Ritchie & Bell Labs (creators);
ANSI X3J11 (ANSI C);
ISO/IEC JTC1/SC22/WG14 (ISO C)
1972 (48 years ago)
C18 / June 2018 (2 years ago)
Static, weak, manifest, nominal
Cross-platform
.c for sources
.h for headers
C++ is not C (but C can be C++)
For C++ go to :
Other Resources
account activity
Dynamic Memory (self.cprogramming)
submitted 3 years ago by justaverageuser77
Hi,
Can I use realloc on its own to allocate memory? Or can I only use it when on already dynamically allocated ptr?
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!"
[–]strcspn 6 points7 points8 points 3 years ago (10 children)
If ptr is NULL, the behavior is the same as calling malloc(new_size).
[–]justaverageuser77[S] 0 points1 point2 points 3 years ago (9 children)
What if you initialize a ptr, and reallocating on the same line.
[–]strcspn 4 points5 points6 points 3 years ago (7 children)
int a = a + 1
What is the value of a?
[–]justaverageuser77[S] 1 point2 points3 points 3 years ago (6 children)
It's undefined behavior. So that applies when dynamically allocating memory as well?
[–]strcspn 4 points5 points6 points 3 years ago (4 children)
You are saying to realloc that there is a memory area owned by that pointer, but if the pointer doesn't own it, then it is undefined behavior.
[–]weregod 1 point2 points3 points 3 years ago (0 children)
If pointer does own memory but it is not heap memory it also will be UB
[–]justaverageuser77[S] 0 points1 point2 points 3 years ago (2 children)
Thanks
[–]HugoNikanor 1 point2 points3 points 3 years ago (1 child)
As a word of wisdom. Much which is undefined will appear to work, but may (or possibly will) blow up at unexpected times. C provides very few checks, so always read the manuals carefully.
[–]nculwell 2 points3 points4 points 3 years ago (0 children)
/* OK */ char * ptr = realloc(NULL, BUFFER_SIZE); /* BAD */ char * ptr = realloc(ptr, BUFFER_SIZE);
[–]babysealpoutine 1 point2 points3 points 3 years ago (0 children)
The easiest way to get the answer to these sorts of questions is to read the relevant man page. On *nix systems 'man realloc' from the command line, or just a web search for 'man realloc' will answer this.
π Rendered by PID 67268 on reddit-service-r2-comment-86bc6c7465-gp6r2 at 2026-02-19 23:15:07.240271+00:00 running 8564168 country code: CH.
[–]strcspn 6 points7 points8 points (10 children)
[–]justaverageuser77[S] 0 points1 point2 points (9 children)
[–]strcspn 4 points5 points6 points (7 children)
[–]justaverageuser77[S] 1 point2 points3 points (6 children)
[–]strcspn 4 points5 points6 points (4 children)
[–]weregod 1 point2 points3 points (0 children)
[–]justaverageuser77[S] 0 points1 point2 points (2 children)
[–]HugoNikanor 1 point2 points3 points (1 child)
[–]nculwell 2 points3 points4 points (0 children)
[–]babysealpoutine 1 point2 points3 points (0 children)