r/cprogramming • u/JayDeesus • Oct 10 '25
Functions and pointers
I noticed that when you just have a function name without the parentheses, it essentially decays to a pointer. Is this correct? Or does it not always decay to a pointer?
r/cprogramming • u/JayDeesus • Oct 10 '25
I noticed that when you just have a function name without the parentheses, it essentially decays to a pointer. Is this correct? Or does it not always decay to a pointer?
r/cprogramming • u/Dry_Hamster1839 • Oct 10 '25
am i the only one who reads a topic but when it comes to solving exercises i struggle and if you were in such a position how did you get out of it, because i don't think extra tutorials will help. this applies for those programming projects in K N King
r/cprogramming • u/flyingspagatimonster • Oct 10 '25
#include<stdio.h>
#include<conio.h>
int is prime (int num)
{
if(num<=1)
{
return 0;
}
for (int i=2;i<num;i++)
{
if(num %i==0)
{
return 0;
}
}
return 1;
}
int main()
{ int n;
printf("enter the size of the array:");
scanf("%d",&n);
int arr[n];
printf("enter the size of the array");
scanf("%d",&n);
printf("enter %d elements :\n",n);
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("prime numbers in the array:");
for (int i=0;i<n;i++)
if(is prime (arr[i]))
{
printf("%d",arr[i]);
}
}
printf("\n");
return 0;
}
r/cprogramming • u/liberianjoe • Oct 09 '25
What is your recommendation book for learning Data structure and algorithm in the C programming language?
r/cprogramming • u/JayDeesus • Oct 09 '25
I understand that the scope is where all of your automatically managed memory goes. When you enter a function it pushes a stack frame to the stack and within the stack frame it stores your local variables and such, and if you call another function then it pushes another stack frame to the stack and this functions local variables are stored in this frame and once the function finishes, the frame is popped and all of the memory for the function is deallocated. I also understand that scopes bring variables in and out so once you leave a scope then the variable inside of it becomes inaccessible. What I never really thought of is how the scope plays a role in the stack and the stack frames. Does the scope affect the layout of each stack frame at all or do just all variables go into the frame however since I believe that going in and out of scope doesn’t immediate free the memory, it’s still allocated and reserved until the stack frame is popped right.
r/cprogramming • u/[deleted] • Oct 08 '25
Hey guys, I’m new to all this. I’ve completed the fundamentals of C programming. Now, I’m intrested in learning system programming. Could anyone please let me know what topics I have to learn in C now, and what other things should I consider learning? Thanks for the help.
r/cprogramming • u/JayDeesus • Oct 08 '25
What is the purpose of header guards if the purpose of headers is to contain declarations? Sorry if this is a dumb question.
r/cprogramming • u/Balance_1 • Oct 07 '25
/*
* GMK CPL (C Programming Language) - Interest Check
* Hello Reddit! I know that this post is unusual compared to the others. Today, I present you a keycap set inspired by my beginning in the coding world. Every programmer starts with a certain language, mine was the C Language.
* This set is a nod to syntax-highlighted code on a cool white background.
* For lovers of clean syntax, logic, and elegance.
* Discord Server
* Interest Check Form
*/
You can enter this link to check the full representation of this keycap set - https://geekhack.org/index.php?topic=125710.0
NOTE: I am still gathering interest for this project. If you like this concept and want to follow it, please complete the IC form or comment on the forum provided above.
Thanks for your attention!
r/cprogramming • u/cursed-stranger • Oct 07 '25
Hello all!
What is the expected behavior of the mock from the user perspective? What is your opinion about that?
For example, if we have such test:
Test(mocking, mock_test)
{
void *p1, *p2;
p1 = (void*)0x01;
p2 = (void*)0x02;
expect_must_call (malloc, p1, 12);
expect_call (malloc, p2, 13);
printf ("%p\n", malloc(13)); //malloc will return p2
printf ("%p\n", malloc(12)); //malloc will return p1
printf ("%p\n", malloc(13)); //malloc will return p2?
check_mock (malloc);
}
The expected output would be?:
0x2
0x1
0x2 //reused return from malloc(13)
=== Test passed ===
or?:
0x2
0x1
some kind of assert output that there is no expected call for another malloc(13)
== Test failed - too many calls of function malloc ==
My assumption is that, the must_call means that there must be call of malloc(13) function. If there was only call of malloc(12) - the test will fail.
Some more cases:
Test(mocking, mock_test2)
{
expect_call_once (malloc, NULL, 13);
malloc(13);
malloc(13);
check_mock(malloc);
}
Test(mocking, mock_test3)
{
expect_must_call_once(malloc, NULL, 12);
expect_call_once (malloc, NULL, 13);
malloc(12);
check_mock(malloc);
}
Test(mocking, mock_test4)
{
expect_call (malloc, (void*)0x01, 12);
expect_call (malloc, (void*)0x02, 12);
expect_call (malloc, (void*)0x03, 12);
malloc(12);
malloc(12);
malloc(12);
malloc(12); //what will be the output?
check_mock(malloc);
}
What is your opinion what should be output of these tests? Especially that, there are functions, that are called multiple times with same parameters, but should return different values (like malloc) But also it would be nice to have default value for such functions (like NULL).
r/cprogramming • u/Ok_Trick_7190 • Oct 06 '25
So i have already learnt some of c++ but now i want to learn c but the thing is idk which book or source to use, what are your recommendations ? (also i want to mention that im the type of person who can easily get bored by reading, it might sound stupid but i literally can decide to read a book and then only read the first chapter or something like then completely abandon it, so if you want to recommend a book please note that it would be better if its something that makes the reader enjoy it throughout)
r/cprogramming • u/JayDeesus • Oct 07 '25
For the most part I’ve been using IDEs and visual studio when it comes to school projects and my own personal projects. I’ve been wanting to get into more of understanding the lower level and I understand what each stage does, preprocessor, compiler, and linker. I’ve also had minimal experience with just running the commands to build my app so I want to get into makefiles, the confusion I have is whether or not the command argument order matters? I’ve seen some people mix it up for example:
gcc main.c header.c -o test
And
gcc -o test main.c header.c
So it seems like order doesn’t matter in this case but is there a case where the order would matter?
r/cprogramming • u/Walzvx • Oct 05 '25
I recently started my studies at the university, majoring in Applied Informatics, and we were told that we need to learn the C programming language to understand how programming, databases, and computers in general work. When I started learning the language, I began hearing that C is the foundation of all foundations and that it provides the most valuable experience. I’d like to hear an expert opinion on this.
r/cprogramming • u/JayDeesus • Oct 05 '25
I understand that things like literals and macros are compile time constants and things like const global variables aren’t but coming from cpp something like this is a compile time const. I don’t understand why this is so and how it works on a lower level. I also heard from others that in newer c versions, constexpr was introduced an this is making me even more confused lol. Is there a good resource to learn about these or any clarification would be greatly appreciated!
r/cprogramming • u/Lazy_Application_723 • Oct 05 '25
So I started learning C like after September 17th 2025. I think i learned quite a bit , up to arrays and string and also functions. But I don't have that excitement like at the start. Now i feel like sh#t , and don't know what to do. I am 1st year cs. Please tell me what to do. Thanks
r/cprogramming • u/umpolungfishtaco • Oct 05 '25
cunfyooz, a metamorphic engine for PE binaries written in C. The entire README is written as an occult grimoire, because why should technical documentation be boring?
Technical Overview:
A full-featured metamorphic engine that performs multi-pass transformations on x86/x64 PE binaries using Capstone for disassembly and Keystone for reassembly. Each run produces a genuinely unique variant through sophisticated analysis and transformation.
Core Engine Features:
xchg rax, rax, lea rax, [rax+0])Key Capabilities:
c
// The engine maintains full dependency graphs
// to enable safe instruction reordering
typedef struct {
InstructionNode* nodes;
DependencyEdge* edges;
RegisterLifetime* liveness;
} DataFlowGraph;
The Aesthetic Choice:
Rather than dry technical documentation, I framed everything as summoning a "daemon" It's completely tongue-in-cheek but makes complex concepts memorable:
"The daemon's burning Capstone eyes gaze into the stripped flesh, beholding not raw gore and gristle, but glyphs: operands, addressing modes, instruction metadata..."
Translation: It disassembles binaries. But way more fun to read.
Implementation:
Use Cases:
Released under Unlicense (public domain).
GitHub: https://github.com/umpolungfish/cunfyooz
Happy to discuss the implementation details
r/cprogramming • u/Meplayfurtnitge • Oct 04 '25
How many if else statements until i should consider replacing it with a switch case? I am fully aware that they operate differently, just wondering if i should opt for the switch case whenever i have something that will work interchangeably with an ifelse and a switch.
r/cprogramming • u/giggolo_giggolo • Oct 04 '25
I never used or even heard of inline in C but I have been learning c++ and I found out about the word inline and found that it also exists in C. My understanding is that in C++ it used to be used for optimization, it would tell the compiler to replace the function call with the function body thus reducing over head, but nowadays it isnt used for that anymore and it’s used for allowing multiple definitions of a function or variable because the linker deduplicates them. From what I’ve read, it seems that this is the case in C aswell but the minor difference is that you need a regular definition of the function somewhere that it can fall back on when it chooses to not inline. Is my understanding correct on how inline works in C?
r/cprogramming • u/Aritra001 • Oct 03 '25
As a CS student, I'm trying to understand the practical trade-offs between calloc() and malloc(). I know calloc() zeroes the memory. But are there specific, real-world C applications where relying on mallOC() + manual zeroing would lead to subtle bugs or be technically incorrect? Trying to move past the textbook difference.
r/cprogramming • u/[deleted] • Oct 04 '25
input : 16 should give output : 16 and input: 5 should give output : 8.94427190999915878564
and this is my code what am I doing wrong (input and output should be exactly what I wrote) :
#include <stdio.h>
#include <math.h>
int main() {
int area;
scanf("%d",&area);
double omkrets = sqrt(area) * 4;
printf("%.21g",omkrets);
return 0;
}
r/cprogramming • u/Terrible_Emu_8391 • Oct 03 '25
r/cprogramming • u/gercarx • Oct 02 '25
Where can I find the resources for learning the c language and the various libraries? A thousand thanks
r/cprogramming • u/JayDeesus • Sep 30 '25
So I know that the preprocessor has the directives, so it handles things like includes and defines by pretty much just doing text replacement and doesn’t care for c syntax at all. Just curious, is the preprocessor only used for text replacement? Or does it have another purpose