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

  • SEARCH
  • Home
  • 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 9277253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:03:37+00:00 2026-06-18T17:03:37+00:00

This is my code: double values[8], cumulative[8]; printf(Enter first decimal number: ); scanf(%f, values[0]);

  • 0

This is my code:

double values[8], cumulative[8];

printf("Enter first decimal number: ");
scanf("%f", values[0]);
printf("values[0] = %g", values[0]);

My problem is that the scanf statement crashes the program, and the second printf is never executed. My original attempt was to fill each slot of the array with a double, but since that didn’t work I simplified the program to this, but this doesn’t work either.

I’m a beginner learning C, so I probably made a stupid mistake I just can’t see. Any help would be appreciated, thanks!

Edit:

Okay, so apparently I need to add an ampersand to the scanf statement. But I thought an array was just a pointer to the first element of the array? Why do I have to use the ampersand?

  • 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-18T17:03:38+00:00Added an answer on June 18, 2026 at 5:03 pm

    scanf("%f", values[0]); – Here address of first element should be passed to scanf. You are passing value of first element which is a garbage value so that it crashed.

    values[0] is *(values + 0), so this will give value of the first element not the address of the first element.

    Do scanf("%lf", &values[0]); or scanf("%lf", (values + 0)); or scanf("%lf", values);

    As it is double use %lf instead of %f.

    One more problem in your program is uninitlized variables. Try to initialize the variable to zero while declaring.

    double values[8] = {0};
    double cumulative[8] = {0};
    

    Acessing some wrong pointer in some place of your code will leads to 100% crash if its initiliazed to zero. Otherwise it will try to access some garbage value pointer which will leads to memory corruption, this sometimes will not crash instead will give unexpected output. But this also has a 50% chance of getting crash, which you are getting now.

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

Sidebar

Related Questions

I'm having a problem with the specific set of values in this code snippet.
Im dividing 2 double values with this code: float final = cw / q
I am currently using this code: assert(isa(values,'double')); assert(size(values, 1) <= 1000); to persuade matlab
I have a class containing a number of double values. This is stored in
I have two double values that are truncated to two decimal spots. Each one
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], int
Consider this code: int main() { int e; prn(e); return 0; } void prn(double
I found this line of code in some code I'm analyzing: Mintau = (double*)
I have this (working) CPU code: #define NF 3 int ND; typedef double (*POT)(double
In code, if I write a code line like this: GClass<Double> x = new

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.