Awesome q2a theme
+1 vote
21 views

What is the output of the following program?

main( )
{
int a = 10;
if ((fork ( ) == 0))
a++;
printf (“%dn”, a );
}
a) 10 and 11
b) 10
C) 11
D) 11 and 11
in Operating System by (8 points) | 21 views

1 Answer

+1 vote

Option A.

The fork system call create child process. When the parent process call fork, it will return child process ID and check it in 'if' condition given in question and gives if condition false. As a result it will directly go to print statement, and print 10. 

On other part child process will excute a++, and a value will be 11. In next print statement of child process will give value as 11.

So output is 10 and 11.

Option A is right.

by (73 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Jul 2020
  1. Shaik Masthan

    39 Points

  2. hiteshpujari

    9 Points

  3. fazin

    7 Points

  4. srestha

    7 Points

  5. gaurav2697

    6 Points

  6. Venkatesh Akhouri

    6 Points

  7. Meghana518

    6 Points

  8. athenahermes

    6 Points

  9. bittujash

    6 Points

  10. Pawan_k

    6 Points

7,560 questions
1,783 answers
10,868 comments
90,493 users