You have a segmentation fault because you give an invalid argument to scanf
:
scanf("%d",&num); // Give the address of the variable you want to set
By the way, you should use:
int main(void)
More Related Contents:
- Getting Error while calculation of two float numbers [closed]
- What is my C code not printing # in staircase pattern, this is from hackerrank, I did not pass all test cases, but i can't point out why?
- C – int is a variable so why not use a variable instead of an int?
- Why is this C code section flagged as bad? [closed]
- Why doesn’t control enter the repeat() function? [closed]
- Intro to programming C
- Why does division result in zero instead of a decimal?
- Why does a C-Array have a wrong sizeof() value when it’s passed to a function? [duplicate]
- Tentative definitions in C and linking
- error: function returns address of local variable
- Why does “++x || ++y && ++z” calculate “++x” first, even though operator “&&” has higher precedence than “||”
- newbie questions about malloc and sizeof
- Array Type – Rules for assignment/use as function parameter
- In C, can a const variable be modified via a pointer?
- Pointers as function arguments in C
- How do we allocate a 2-D array using One malloc statement
- scanf won’t ask for input the second time [duplicate]
- What is a simple and reliable C library for working with Excel files? [closed]
- Best practice for compute the function return value
- What do square brackets mean in array initialization in C?
- Where can one find the C89/C90 standards in PDF format?
- How can I work with dynamically-allocated arbitrary-dimensional arrays?
- Is my fma() broken?
- Why does gdb evaluate sqrt(3) to 0?
- How to use timer in C?
- C – Serialization of the floating point numbers (floats, doubles)
- When printf is an address of a variable, why use void*?
- How do I get bit-by-bit data from an integer value in C?
- Is ‘long unsigned’ as valid as ‘unsigned long’ in C?
- Integer overflow in C: standards and compilers