ExpertUdayan Shakya
Technical Content Writer @Programiz
Answered 18 questions
About

When you use fptr == NULL, you're actually checking if fptr is equal to the special value NULL, which indicates that no file was opened successfully at that pointer.
Basically, fopen() is designed to either:
return a pointer to a
FILEobject representing the file you want to work with,or, if there's an error (like if the file isn't found), it returns
NULL.The value
NULLin this context signals that the pointerfptrdoesn't point to any valid file, allowing you to safely check if the file operation succeeded.
In other words, NULL isn't just an ordinary value; it's actually a special marker that's treated differently from ordinary literals such as 1, 0, "yes", "no", etc.
That's why you can indeed check fptr == NULL but can't do checks such as fptr == "yes" since that's not allowed in pointer operations.
Hope this helps you understand the behavior of NULL and pointers better! Let me know if you have any more questions.

Hi again! A short answer to this particular question is included in my answer to your previous question.
If you're still confused, you can try the following program and see what happens:
#include <stdio.h>
int main() {
int age;
// get age input
printf("Enter age: ");
scanf("%d\n", &age);
// print age
printf("Age: %d", age);
return 0;
}You'll see that this program "hangs" after you've entered the age and pressed enter, i.e., it doesn't print the age after you've given the input.
The only way to make it print the age is to give another input and press enter. Here's my full output:
Enter age: 25
a
Age: 25Notice that I had to enter a (or any other non-whitespace input) to print the age.
Obviously, this is bad because the program appears to be hanging/freezing in the middle of the execution.
And as I've explained in my previous answer, this happens because you're telling scanf() to consume all whitespace characters and wait for non-whitespace character input.
That's what scanf("%d\n", &variable); does, and it's not something you want in your code.
Hope this helps! Let me know if you have any more questions.

Hi there! At first glance, your code appears to make intuitive sense. But thanks to the way C programming functions internally, you've ended up with several problems in your code.
The two major issues are:
1. Using \n with scanf
Here's how you've taken input for age:
scanf("%d\n", &enployee1.age);Please don't do this. In scanf format strings, whitespace characters (including \n) mean: consume any amount of whitespace, then keep waiting until the next non-whitespace character appears.
So scanf("%d\n", ...) will:
read the integer,
then consume the newline you typed,
and then block until you type the first non-whitespace character of the next input (for example, the first letter of the name).
To fix this, please remove \n from this code like this:
scanf("%d", &enployee1.age);Then consume the leftover newline before reading a line of text:
getchar(); Here, getchar() will consume the newline character \n entered after the age input so it doesn't interfere with the next input statement.
2. Getting individual character input for "name" and printing the individual characters instead of printing the name as a single string.
On the surface, it makes sense to use a loop to get individual character inputs for a string (since scanf() can only take input for a single word).
But there are many problems with this:
Using a loop from 0 to 49 means the code will always take input for 50 characters, even if the actual name contains far less characters (say, 20 characters). This is wasteful.
This loop also doesn't add a null terminating character
\0at the end of the string.Printing each character of the string is not ideal. It's better to print the entire name as a string rather than individual characters.
To fix this, please use fgets() to get string input like this:
fgets(employee1.name, sizeof(employee1.name), stdin);A Minor Spelling Mistake
You've misspelled Employee by writing it as Enployee, and your object names also have this mistake.
This doesn't matter within the code but it's still better to use proper spellings.
Full Solution
#include <stdio.h>
// create Person struct
struct Employee {
int age;
char name[50];
};
int main() {
// create struct variable
struct Employee employee1;
// get age input for employee1's age
scanf("%d", &employee1.age);
// use getchar() to consume the newline
getchar();
// get name input for employee1's name
fgets(employee1.name, sizeof(employee1.name), stdin);
// print name and age
printf("%s", employee1.name);
printf("%d", employee1.age);
return 0;
}
Hello there! It's natural to be confused about the sizeof operator in C, and whether it includes the null terminator as well.
To answer your question: no, we don't need to write sizeof(name) + 1 because sizeof measures the full size of the variable (in bytes), which includes the null terminator as well.
Hope that helps! Contact us again if you have further questions.

Hi Alan, that’s a great question.
In Python, powers work a little differently from what you see on most calculators. Calculators usually use the ^ symbol for exponents, so it’s normal to try the same thing in Python. The tricky part is that Python doesn’t use ^ for powers at all, so it won’t give the result you expect.
The Python way to calculate a power is with two stars. So if you want “4 to the power of 3,” you write:
4 ** 3
Python reads that as “multiply 4 by itself three times,” which gives:
4 * 4 * 4 = 64
You can do the same with decimals:
2.5 ** 3 # 15.625
Once you get used to **, it becomes pretty straightforward.
If you have more questions while you’re learning, I’m happy to help.

Hi Harkirat,
Great question — it’s something many learners wonder about.
When you write:
int intValue = (int) doubleValue;
the part (int) is called explicit type casting. You're telling the compiler clearly: "Yes, I know doubleValue is a double, and I want to convert it to an integer."
Even though you're storing the result in an int, if you skip the cast:
int intValue = doubleValue;
C will do an implicit conversion — it still works, but the compiler may give you a warning, especially if there’s a chance of losing data (like dropping decimal points).
Using (int) makes your intention clear and avoids confusion. It’s also a good habit when converting between types, especially when precision matters.
If you have more questions, I am here to help.

Hi Nayaz,
Good question. You’re right that the code will still run without the f, but here’s what’s really happening:
When you write:
float n = 1.2;
the value 1.2 is treated as a double by default. Then it's converted to a float, which can lead to a small precision loss — because double uses 8 bytes, while float uses only 4.
If you write:
float n = 1.2f;
you’re telling the compiler directly: “this is a float value,” and it avoids any unnecessary type conversion or warning.
So while the f isn’t strictly required, it’s considered good practice when assigning float literals.
If you have more questions, I am here to help.

Hi Reyann,
Good question. If you’re seeing both double i; and int i in the same code, here’s what’s happening:
The double i is declared outside the for loop, and the int i is declared inside the loop. In C, variables declared inside a block (like a loop) are separate from those outside — even if they have the same name.
So when you write:
double i = 3.5;
for (int i = 0; i < 5; i++) {
// this 'i' is a different variable
}
The int i inside the loop is its own separate variable, and it temporarily hides the double i. That’s why the compiler doesn’t complain — it’s allowed, but it can be confusing.
Best practice: avoid using the same variable name in different scopes unless there’s a good reason.
If you have more questions, I am here to help.