system function in c

What is system() in c programming?

system function in c is used to run Shell commands which cannot be directly executed by the c program.

This function is defined in stdlib.h header file.

Prototype

int system(char const *COMMAND);

Return value

It returns status of the command or -1 on error.


Example program for system() in c

#include<stdio.h>
#include<stdlib.h>
int main()
{
  if(system(NULL)==0)
   printf("command processor is not present \n");
  else
    system("ls");
  return 0;
}

Output

system in c output
system function in c output

Code explanation

The system() executes the shell command “ls”, if it is present on your system.


People Also Ask for

What does system() returns?

This function executes shell commands if they are present on your system.