cvisual-studio-codegccvscode-code-runner

Compiling C Program in VS code using Code runner


I have written a simple c program and given it a name of program When The code is made to run using code runner extension it uses this kind of statement

PS C:\Users\user_name> cd "c:\Users\user_name\Desktop\" ; if ($?) { gcc program.c -o program } ; if ($?) { .\program }

In this i could understand ( gcc program.c -o program ) but what does if ($?) and if($?) {.\program } mean ?


Solution

  • if($?) means if the previous step is successful

    PS C:\Users\user_name> cd "c:\Users\user_name\Desktop\" ; if ($?) { gcc program.c -o program } ;
    

    here if ($?) means if there exists a file named program.c then compile using the command

    gcc program.c -o program
    

    so does the next line,

    if ($?) { .\program }
    

    if the executable file is succesfully created then run the executable file using .\program command