Storage class in C programming defines scope and lifetime of a variable and function. At the time of variable declaration we define both data type as well as storage class of a variable.
Global variables in C
Global variables are variables declared outside a function. Unlike local variables and static variables, a global variable is not declared inside a function.
Static variables in C
Static variables are declared with static
keyword. Static variables have an essential property of preserving its value across various function calls. Unlike local variables, static variables are not allocated on C stack. Rather, they get their memory in data segment of the program.
Local variables in C
Quick links
Local variables are variables declared within a function or more specifically say within a block.
Block is a sequence of statements grouped together inside a pair of curly braces {
and }
. Since the first day of programming, you have been using blocks. For example – if…else block, loop block, function block etc.
Variable length arguments (var-args) in C
Quick links
In the journey of learning C functions, we learned many concepts related to functions. We learned to define our own function, passing arguments to a function, returning value from a function, recursive function etc. In this chapter, I will talk something interesting about passing variable length arguments to a function.
Have you ever wondered how functions like printf()
and scanf()
works? As they readily accept any number of arguments passed. You can say –
printf("Learning at Codeforwin"); // Single argument
printf("Codeforwin was founded in %d", 2015); // Two arguments
printf("Today is %d-%d-%d", 19, 9, 2017); // Four arguments
In real you can pass n number of arguments to printf()
, but how it works?
C program to print hollow square star pattern with diagonal
Write a C program to print hollow square star pattern with diagonal using loops. How to print hollow square star pattern with diagonals in C program. Logic to print hollow square star pattern with diagonal in C programming.
Recursion in C programming
Recursion is expressing an entity in terms of itself. In C programming, recursion is achieved using functions known as recursive function. Recursive functions are very powerful in solving and expressing complex mathematical problems.
Until now, we called a function from another function. However, C language allows a function to call itself known as Recursive function.
Types of functions in C
Quick links
A function is a sub-part of a program that contains a collection of statements grouped together to perform some specific task. Functions in C programming is categorized in two category –
return statement in C
A function is a collection of statements grouped together to do some specific task. It may return a value. However, in no case a function will return more than one value. What does it mean by returning a value and where it is returned? To understand this let us consider an example.
Function arguments in C – Call by value and Call by reference
Quick links
Function arguments are the inputs passed to a function. A function must declare variables to accept passed arguments. A variable that accepts function argument is known as function parameter.
In programming function argument is commonly referred as actual parameter and function parameter is referred as formal parameter. I will be using these words interchangeably throughout this series of C programming tutorial.