Ask Programiz - Human Support for Coding Beginners
Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.

Hello Varun, really nice question.
A lot of beginners run into this when they start working with functions in C, so youâre definitely on the right track noticing it.
Hereâs the simple idea:
If you write a function like this:
int getProduct(float a, float b)
C expects that function to return an int, no matter what you actually calculate inside it. So even if a * b produces a floating-point value, C will convert it to an integer when returning it. Thatâs why the decimal part disappears.
If you want the full, precise result, you need the function to return a floating-point type:
double getProduct(double a, double b) {
return a * b;
}
This keeps the decimal values and avoids losing accuracy.
And one more thing students often miss:
You have to actually use the returned value, otherwise it's wasted:
double result = getProduct(3.5, 4.6);
printf("Product: %.2f\n", result);
If anything about return types still feels unclear, feel free to ask â Iâm happy to help you understand it fully.

Hello Ivan, really nice question.
Itâs easy to mix up the idea of a function âreturningâ with what \n does in a print statement. They sound similar, but theyâre completely different things.
When you write:
printf("Hey\nHow are you?");
the \n does not return from the function. It doesnât stop anything, and it doesnât exit the print. All it does is tell the output: start a new line here. So the text comes out like this:
Hey
How are you?
The printing continues normally after the newline.
A real return is something you do with a return statement inside a function, not with \n.
If you want more examples or want to see how multiple \n behave, Iâm happy to show you.

Hello Zade, really nice question.
The reason the function is defined as int instead of void is that it actually produces a value â the sum. Whenever a function calculates something and you want to use that result later in the program, the function needs a return type that matches the kind of value it gives back. In this case, the sum of natural numbers is an integer, so the function returns an int.
A void function is different. It performs an action but doesnât hand anything back. For example, a function that only prints something to the screen doesnât need to return a value, so void makes sense there.
So the rule is simple:
If the function gives back a value, choose a matching return type.
If it doesnât return anything, use void.
If you have further questions, I'm here to help.

Itâs not a bug. Your count never changes, so count <= 3 stays true forever.
Buggy code:
#include
int main() {
int count = 1;
while (count <= 3) {
printf("I am inside a loop.\n");
printf("Looping is interesting.\n");
}
return 0;
}
Output (repeats forever):
I am inside a loop.
Looping is interesting.
...
Fix:
#include
int main() {
int count = 1;
while (count <= 3) {
printf("I am inside a loop.\n");
printf("Looping is interesting.\n");
count = count + 1;
}
return 0;
}
Output:
I am inside a loop.
Looping is interesting.
I am inside a loop.
Looping is interesting.
I am inside a loop.
Looping is interesting.
If you have more questions, I am here to help.

Hi Harkirat, in C, isdigit() returns 0 for false and any non-zero number for true, and the exact âtrueâ number can be different depending on the system. So 2048 still just means true.
printf("%d\n", isdigit('8')); // non-zero means true (could be 2048)
If you have more questions, I am here to help.

Hi Sanskriti,
Great question. A function doesnât need a return statement to run, but whether or not you use it depends on what the function is supposed to do.
If a function is only doing a task (like printing something or updating a value) and isnât meant to give anything back, you donât need a return value â that's when you define it with void.
But if you want the function to send a result back to the place it was called from, you need a return statement.
Hereâs an example:
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 5);
printf("%d", result); // Output: 8
return 0;
}
The add function returns the sum of two numbers. That return value is stored in result and printed. Without return, the function wouldnât send anything back, and you'd have nothing to work with.
Also, if you declare a function to return a value (like int, float, etc.) but forget to use return, you might get incorrect results or even undefined behavior.
So in short:
Use
returnwhen you need a result from the function.Skip it if the function is just doing something and doesnât need to report back.
If you have more questions, Iâm here to help.

Hi MÄrtiĆĆĄ,
Variables are called temporary because they only exist while the program is running. They're used to store values in memory that your program needs at that moment â like numbers, strings, or results from calculations.
Hereâs a simple example:
int main() {
int score = 0;
score += 10;
printf("Current Score: %d\n", score);
return 0;
}
In this code, the variable score holds a value temporarily. Once the program finishes running, the data stored in score is gone â unless you explicitly save it somewhere, like a file or database.
So to sum up: variables help your program work with data during execution, but they don't keep that data permanently.
If you have more questions, Iâm here to help.


Hi Soumyadeep,
Yes, itâs easier than it seems! Letâs take a simple example using the OR operator (||), which is one kind of logical gate.
The OR operator checks two conditions and gives true if at least one of them is true.
Hereâs how it works in code:
if ((age >= 18) || (gpa > 3.5)) {
printf("You meet the criteria.\n");
}
This line means:
âIf the person is 18 or older, or their GPA is above 3.5, then print the message.â
Examples:
If age is 20 and GPA is 3.0 â it prints (because age â„ 18)
If age is 16 and GPA is 3.8 â it prints (because GPA > 3.5)
If age is 16 and GPA is 3.0 â it doesnât print (because both are false)
So in simple terms:
OR means only one condition needs to be true for the code to run.
Let me know if you want help understanding other gates like AND or NOT â Iâm here to help.

Hi Jayadithya,
Great question â this trips up a lot of learners.
The sizeof() operator does return the correct value â it gives you the size of a type or variable in bytes. But hereâs the key part:printf() doesnât know what type you're printing unless you tell it using a format specifier.
So even if sizeof(int) returns a valid number like 4, you still need to use %d or %lu (depending on your system and compiler) to tell printf how to interpret and display that value.
Now, about using different format specifiers â yes, thatâs sometimes intentional. For example:
char ch = 'A';
printf("%d", ch); // Prints 65 instead of 'A'
Here, %d is used to show the numeric (ASCII) value of the character, not the character itself.
So to sum up:
sizeof()works fine â the issue is with how you choose to print the result.Sometimes, using a "wrong" format specifier is done on purpose to view data differently.
If you have more questions, I am here to help.


In C, when you use a comparison like total > 100, it doesnât return true or false as words â it returns a number:
1if the condition is true0if itâs false
So if you write:
result = total > 100;
C checks if total is greater than 100. If it is, result becomes 1. If not, result becomes 0.
Thatâs why the output is either 0 or 1 â it's just how C handles boolean logic under the hood.
If you have more questions, I am here to help.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer

