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 Java Programming
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 - Variable Number of Arguments - Discussion

@ : Home > C Programming > Variable Number of Arguments > Find Output of Program - Discussion

Read more:

"Everyone is wise until he speaks."
- (Proverb)
3. 

What will be the output of the program?

#include<stdio.h>
#include<stdarg.h>
void dumplist(int, ...);

int main()
{
    dumplist(2, 4, 8);
    dumplist(3, 6, 9, 7);
    return 0;
}
void dumplist(int n, ...)
{
    va_list p; int i;
    va_start(p, n);

    while(n-->0)
    {
        i = va_arg(p, int);
        printf("%d", i);
    }
    va_end(p);
    printf("\n");
}

[A]. 2 4
3 6
[B]. 2 4 8
3, 6, 9, 7
[C]. 4 8
6 9 7
[D]. 1 1 1
1 1 1 1

Answer: Option B

Explanation:

No answer description available for this question.


Pooja said: (Thu, Aug 5, 2010 01:47:29 PM)    
 
Please describe how to solve this problem.

Raj said: (Sat, Jul 30, 2011 02:04:07 PM)    
 
First dumplist function is called with elements 2, 4 and 8. When va_start is called, it points to element 2.

When it sees va_arg, it points to the next element 4.

Since va_arg is within while loop, it prints 4 8 for the first function and 6 9 7 for the second function.

So the answer is option C.

Prince Bhanwra said: (Fri, Oct 21, 2011 04:36:10 PM)    
 
what does while loop condition indicates??

i.e. while(n-->0)

what this condition indicates????

Anil said: (Tue, Jan 3, 2012 05:14:05 PM)    
 
while(n-- >0) ...loop until the value of n is greater than 0. I think here n represents the no of arguments passed excluding n.

Write your comments here:
Name *:     Email:


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

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