Found 1401 Articles for C

What is evaluation order of function parameters in C?

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

419 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

Creating multiple process using fork() in C

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

2K+ Views

In this section we will see how to use the fork() to make child process in C. We also do some different tasks in each process. So in our parent process we will print different values.When fork() is called, it returns a value. If the value is greater than 0, then currently it is in parent process, otherwise it is in child process. So using this we can distinguish between the processes.Example Code#include #include int main() {    int n = fork(); //subdivide process    if (n > 0) { //when n is not 0, then it is ... Read More

What is Dynamic Memory Allocation in C?

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

2K+ Views

Here we will see what is dynamic memory allocation in C. The C programming language provides several functions for memory allocation and management. These functions can be found in the header file. The following functions for memory allocations.FunctionDescriptionvoid *calloc(int num, int size);This function allocates an array of num elements each of which size in bytes will be size.void free(void *address);This function releases a block of memory block specified by address.void *malloc(int num);This function allocates an array of num bytes and leave them uninitialized.void *realloc(void *address, int newsize);This function re-allocates memory extending it upto newsize.Allocating memory dynamicallyWhile programming, if you ... Read More

Get and Set the stack size of thread attribute in C

Smita Kapse
Updated on 30-Jul-2019 22:30:25

1K+ Views

To get and set the stack size of thread attribute in C, we use the following thread attributes:pthread_attr_getstacksize()Use for get threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. In case of a successful run, then it gives 0 otherwise gives any value.It takes two arguments −pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)First one for pthread attribute.Second one for giving the size of the thread attribute.pthread_attr_setstacksize()Used for set new threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. In case of a successful run, then it gives 0 otherwise it gives ... Read More

Octal literals in C

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

4K+ Views

In C/C++ we can use octal literals by typing a zero before the actual number. For example, if an octal number is 25, then we have to write 025.Example Code#include int main() {    int a = 025;    int b = 063;    printf("Decimal of 25(Octal) is %d", a);    printf("Decimal of 63(Octal) is %d", b); }OutputDecimal of 25(Octal) is 21 Decimal of 63(Octal) is 51

SQL using C/C++ and SQLite

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

2K+ Views

In this section, you will learn how to use SQLite in C/C++ programs.InstallationBefore you start using SQLite in our C/C++ programs, you need to make sure that you have SQLite library set up on the machine. You can check SQLite Installation chapter to understand the installation process.C/C++ Interface APIsFollowing are important C/C++ SQLite interface routines, which can suffice your requirement to work with SQLite database from your C/C++ program. If you are looking for a more sophisticated application, then you can look into SQLite official documentation.Serial NoAPI & Description1sqlite3_open(const char *filename, sqlite3 **ppDb)This routine opens a connection to an SQLite ... Read More

How to execute zombie and orphan process in a single C program?

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

1K+ Views

In this section we will see how to execute zombie process and orphan process in a single program in C/C++. Before going to the main discussion, let us see what are the zombie process and orphan process.Zombie ProcessesA zombie process is a process whose execution is completed but it still has an entry in the process table. Zombie processes usually occur for child processes, as the parent process still needs to read its child’s exit status. Once this is done using the wait system call, the zombie process is eliminated from the process table. This is known as reaping the ... Read More

Advertisements