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:

"It takes a very long time to become young."
- Pablo Picasso
4. 

What will be the output of the program?

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

int main()
{
    display(4, 'A', 'B', 'C', 'D');
    return 0;
}
void display(int num, ...)
{
    char c, c1; int j;
    va_list ptr, ptr1;
    va_start(ptr, num);
    va_start(ptr1, num);
    for(j=1; j<=num; j++)
    {
        c = va_arg(ptr, int);
        printf("%c", c);
        c1 = va_arg(ptr1, int);
        printf("%d\n", c1);
    }
}

[A]. A, A
B, B
C, C
D, D
[B]. A, a
B, b
C, c
D, d
[C]. A, 65
B, 66
C, 67
D, 68
[D]. A, 0
B, 0
C, 0
C, 0

Answer: Option C

Explanation:

No answer description available for this question.


Naveen said: (Wed, Sep 15, 2010 10:31:05 AM)    
 
Can someone tell how this code works??

Sankar said: (Fri, Oct 22, 2010 08:15:47 AM)    
 
Here ptr and ptr1 are separate va_list,
ptr reads the parameter and displays in char format, and
ptr1 reads the parameter and displays in int format i.e. ASCII of A, B, C, and D.

Priya said: (Tue, Jul 26, 2011 10:52:11 PM)    
 
I didn get you. Can you please explain more clearly.

Pulkit Aggarwal said: (Sun, Aug 7, 2011 08:37:55 PM)    
 
The function va_arg() extracts the argument from the argument list and advances the pointer to the next argument .

Here initially c=A and c1=A (but since it is %d therefore its ASCII value is printed).

Preety said: (Wed, Nov 16, 2011 06:28:13 PM)    
 
va_list ptr, ptr1;
va_start(ptr, num);
va_start(ptr1, num);


Can anybody please tell me what's the purpose of this thing in code?

Nuzhat said: (Tue, Dec 6, 2011 02:43:30 PM)    
 
va_list ptr n prt1 are argument pointer to traverse through the variable arguments passed in the function....
va_start points ptr n ptr1 to the argument...in this case 4...

Vanita said: (Thu, Feb 9, 2012 11:58:20 AM)    
 
I did not understand this problem. Can anyone explain it briefly?

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!