IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Functions - Discussion

@ : Home > C Programming > Functions > Find Output of Program - Discussion

Read more:

"Nothing in life is to be feared, it is only to be understood."
- Marie Curie
14. 

What will be the output of the program?

#include<stdio.h>
int func1(int);

int main()
{
    int k=35;
    k = func1(k=func1(k=func1(k)));
    printf("k=%d\n", k);
    return 0;
}
int func1(int k)
{
    k++;
    return k;
}

[A]. k=35[B]. k=36
[C]. k=37[D]. k=38

Answer: Option A

Explanation:

Step 1: int k=35; The variable k is declared as an integer type and initialized to 35.

Step 2: k = func1(k=func1(k=func1(k))); The func1(k) increement the value of k by 1 and return it. Here the func1(k) is called 3 times. Hence it increements value of k = 35 to 38. The result is stored in the variable k = 38.

Step 3: printf("k=%d\n", k); It prints the value of variable k "38".


Priya said: (Thu, Nov 17, 2011 07:07:17 PM)    
 
There is a postfix increment operator so the value should not increase before going to the caller function so there should not be any increment in value.

Rupinder said: (Fri, Dec 2, 2011 11:19:22 PM)    
 
@priya: No you are wrong.If the return statement would be like return(k++),then answer should be 35.But here,in this case,first k is post incremented and in next step return(k++) it actually incremented and return incremented value.

Siva Selagala said: (Thu, Sep 20, 2012 12:26:53 PM)    
 
The difference is: if p=12 then
k=++p;then k value first assiened to 13(k=13)
k=p++;then k value asigned to 12(k=12)
Like that we can calculate

Preethiraju said: (Tue, Dec 18, 2012 09:24:25 PM)    
 
Can anyone explain me the execution of this statement:

k = func1(k=func1(k=func1(k)));

It works by first calling the internal function call or not?

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!