C Articles

Page 94 of 96

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

Vrundesha Joshi
Vrundesha Joshi
Updated on 30-Jul-2019 2K+ 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

Get and Set the stack size of thread attribute in C

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 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

Creating multiple process using fork() in C

Nitya Raut
Nitya Raut
Updated on 30-Jul-2019 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

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

Vrundesha Joshi
Vrundesha Joshi
Updated on 30-Jul-2019 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

How to Count Variable Numbers of Arguments in C?

Nitya Raut
Nitya Raut
Updated on 30-Jul-2019 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

What is evaluation order of function parameters in C?

Jennifer Nicholas
Jennifer Nicholas
Updated on 30-Jul-2019 703 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

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

Jennifer Nicholas
Jennifer Nicholas
Updated on 30-Jul-2019 413 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

C/C++ Struct vs Class

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 466 Views

In C++ the structure and class are basically same. But there are some minor differences. These differences are like below.The class members are private by default, but members of structures are public. Let us see these two codes to see the differences.Example#include using namespace std; class my_class {    int x = 10; }; int main() {    my_class my_ob;    cout

Read More

Benefits of C over other languages\\n

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 2K+ Views

The C programming language was developed by Dennis Ritchie during early 1970. It was developed to redesign UNIX operating system.Earlier the B language, which was used for UNIX system, it has different drawbacks. It does not support structures, and did not understand datatypes. For this reason, the C language was introduced. C has high level functionality, and detailed feature for OS programming. The UNIX kernel was developed by using C.Advantages of C languageC is medium level language. It has both, the lower level and higher level functionality. We can use C to make driver or kernel level programs as well ...

Read More

Scansets in C

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 4K+ Views

Let us see, what is the scanset in C. The scanset is basically a specifier supported by scanf family functions. It is represented by %[]. Inside scanset we can specify only one character or a set of characters (Case Sensitive). When the scanset is processed, the scanf() can process only those characters which are mentioned in the scanset.Example#include int main() {    char str[50];    printf("Enter something: ");    scanf("%[A-Z]s", str);    printf("Given String: %s", str); }OutputEnter something: HElloWorld Given String: HEIt ignores the characters which are written in lowercase letters. The ‘W’ is also ignored because there are some ...

Read More
Showing 931–940 of 953 articles
Advertisements