Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:17:47+00:00 2026-06-11T23:17:47+00:00

When I run this sample program using va_arg(ap,double), I found va_arg return invalid data,

  • 0

When I run this sample program using va_arg(ap,double), I found va_arg return invalid data, as 0 instead of 3 or 1.2 instead of 1, such that if I pass integer value without .00 instead of double format it get a garbage data (ie 3 instead of 3.00)!!!

#include <stdio.h>
#include <stdarg.h>
void func(int s){
    printf("%s: %d\n",__func__,s);
}

void var(int count,...){
    va_list ap;
    va_start(ap,count);
    double a = va_arg(ap,double);
    printf("%f\n",a);
    va_end(ap);

}

void main(void ) {
    printf("%s,%d,%s\n",__FILE__,__LINE__,__DATE__);
    func(__LINE__);
    var(1,3);
    var(1,1.2);
    var(1,1);

}

The Output is:

try.c,24,Sep 25 2012
func: 25
0.000000
1.200000
1.200000
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:17:48+00:00Added an answer on June 11, 2026 at 11:17 pm

    Variadic functions (that is, functions which take a variable number of arguments indicated by the ellipsis (...) parameter) have weak typing in C. Except in the case of certain special functions like printf and scanf, the compiler makes no effort to verify that you’re passing the correct types of arguments to them.

    In your case, the function is expecting a double parameter, but you’re trying to pass in an int. The compiler does not do any promotion here from int to double, so undefined behavior results. You need to always pass in a double value here, either as an explicit double constant value such as 1.0, or perform the conversion using a typecast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've encounter a weird problem with C# threading. This is my sample program using
Thanks in advance. This is my sample code. Whenever i try to run it
I am trying to run a sample project from This site . Jboss starts
What's the fastest way using either DOS scripting or PowerShell to run this simple
I'm going to run this really simple cod that will be compiled in visual
I just started learning C++ and I wrote this sample program from the text
Let's take this code sample : using System; using System.IO; namespace ConsoleApplication25 { class
I am doing currently a sample exercise and i found one weird observation that
I am working on a Java program and using Timer objects to run tasks
I am using an example program from this code http://sicktoolbox.sourceforge.net/ > http://sourceforge.net/projects/sicktoolbox/files/ . It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.