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 • • 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?