Found 33676 Articles for Programming

Is there a performance difference between i++ and ++i in C++ program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

2K+ Views

The effective result of i++ and ++i are same. The only difference is that the i++ increases the value of i after assigning it, and for ++i, it increases the value first, then assigns its value. We can see the difference in the following code.Example Code#include using namespace std; int main() {    int x = 3, y, z;    y = x++;    z = ++x;    cout

_Noreturn function specifier in C

Ravi Ranjan
Updated on 11-Jul-2025 18:16:55

231 Views

The _Noreturn function specifier in C indicates to the compiler that the function will either exit or run in an infinite loop. This function never returns the control to the main function or wherever it was called in the program. If the _Noreturn function uses the return statement, the compiler will generate a warning or show an undefined behavior. Syntax of _Noreturn Function Specifier The syntax of _Noreturn function specifier is given below: _Noreturn data_type function_name() { --- code lines --- } _Noreturn with exit() Function in ... Read More

What happens when a function is called before its declaration in C?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

334 Views

If we do not use some function prototypes, and the function body is declared in some section which is present after the calling statement of that function. In such a case, the compiler thinks that the default return type is an integer. But if the function returns some other type of value, it returns an error. If the return type is also an integer, then it will work fine, sometimes this may generate some warnings.Example Code#include main() {    printf("The returned value: %d", function); } char function() {    return 'T'; //return T as character }Output[Error] conflicting types for 'function' ... Read More

What is the purpose of a function prototype in C/C++?

Aman Kumar
Updated on 12-Jun-2025 14:58:45

6K+ Views

In this article, we will explore the purpose of using function prototypes in C or C++. What are Function Prototypes? The function prototypes tell the compiler about the number of arguments and the required data types of function parameters; they also tell the compiler about the return type of the function. With this information, the compiler cross-checks the function signatures before calling it. If the function prototypes are not mentioned, then the program may be compiled with some warnings and sometimes generate some strange output. Purpose of a Function Prototype When a function is called before it is defined, and ... Read More

How can we return multiple values from a function in C/C++?

Aman Kumar
Updated on 18-Jun-2025 18:38:24

28K+ Views

In C or C++, we cannot return multiple values from a function directly. In this Article, we will see how to use some trick to return more than one value from a function. Returning Multiple Values from a Function We can return multiple values from a function by using the method. Below is the list of methods that are used to return multiple values from a function in C/C++: Using Pointers Using Structures Using Arrays Returning Multiple Values Using Pointers Pass the arguments by their addresses ... Read More

What is evaluation order of function parameters in C?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

621 Views

We pass different arguments into some functions. Now one questions may come in our mind, that what the order of evaluation of the function parameters. Is it left to right, or right to left?To check the evaluation order we will use a simple program. Here some parameters are passing. From the output we can find how they are evaluated.Example Code#include void test_function(int x, int y, int z) {    printf("The value of x: %d", x);    printf("The value of y: %d", y);    printf("The value of z: %d", z); } main() {    int a = 10;    test_function(a++, a++, ... Read More

How to Count Variable Numbers of Arguments in C?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

2K+ Views

In this section we will see how to count number of arguments in case of variable number of arguments in C.The C supports ellipsis. This is used to take variable number of arguments to a function. User can count the arguments by using one of the three different ways.By passing the first argument as count of the parametersBy passing last argument as NULL.Using the logic like printf() or scanf() where the first argument has the placeholders for other arguments.In the following program, we will total number of variable of arguments passed.Example Code#include #include int get_avg(int count, ...) {   ... Read More

Functions that are executed before and after main() in C

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

3K+ Views

Here we will see how to write a code where two functions are present, and one function will be executed before the main function, and another function will be executed after the main function. These features are used to do some startup task before executing the main, and some cleanup task after executing main.To do this task we have to put attribute for these two functions. When the attribute is constructor attribute, then it will be executed before main(), and when the attribute is destructor type, then it will be executed after main().Example Code#include void before_main() __attribute__((constructor)); void after_main() __attribute__((destructor)); ... Read More

Importance of function prototype in C

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

5K+ Views

Here we will see why we should use function prototype in C. The function prototypes are used to tell the compiler about the number of arguments and about the required datatypes of a function parameter, it also tells about the return type of the function. By this information, the compiler cross-checks the function signatures before calling it. If the function prototypes are not mentioned, then the program may be compiled with some warnings, and sometimes generate some strange output.If some function is called somewhere, but its body is not defined yet, that is defined after the current line, then it ... Read More

Random number generation in C++

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

296 Views

Let us see how to generate random numbers using C++. Here we are generating a random number in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below:void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number we ... Read More

Advertisements