Variable length arguments (var-args) in C

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?

Continue reading Variable length arguments (var-args) in C

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.

Example
Input

Enter number of rows: 5

Output

Continue reading C program to print hollow square star pattern with diagonal

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.

Continue reading Recursion in C programming

Function arguments in C – Call by value and Call by reference

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.

Continue reading Function arguments in C – Call by value and Call by reference

Functions in C programming

A function is a collection of statements grouped together to do some specific task. In series of learning C programming, we already used many functions unknowingly. Functions such as - printf(), scanf(), sqrt(), pow() or the most important the main() function. Every C program has at least one function i.e. the main() function.

Continue reading Functions in C programming

Infinite loops in C – Use and Debugging

Infinite loop is a looping construct that iterates forever. In programming life either intentionally or unintentionally, you come across an infinite loop. Generally a program in an infinite loop either produces continuous output or does nothing. Infinite loops are also known as indefinite or endless loop.

As a novice programmer, you must know how to debug an infinite loop. As an intermediate programmer you must know how and when to use infinite loop. Let us first learn when to use infinite loop and how to define.

Continue reading Infinite loops in C – Use and Debugging

goto statement in C

goto is a jump statement used to transfer program control unconditionally from one part of a function to another. I have used the word unconditionally because there is no restriction on control transfer. You can transfer program control from one position to any position within a function. Many programmers uses goto to gain full control on their program.

Continue reading goto statement in C