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 6788073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:26:28+00:00 2026-05-26T17:26:28+00:00

I am trying to learn arrays and pointers in C. I’m trying to write

  • 0

I am trying to learn arrays and pointers in C. I’m trying to write a program that in a function: gets 2 numbers from the user, puts them in an array, and returns them to the main function. I am getting an error and I don’t understand what the problem is. Here is my code:

#include<stdio.h>

void get_nums(float *x)
{
    float num1, num2;

    printf("enter two numbers: ");
    scanf("%f %f", &num1, &num2);

    *x[0] = num1;
    *x[1] = num2;

}

main(){

    float x[2];
    float (*p_x)[2] = &x;

    get_nums(p_x[2]);

    printf("Number 1: %f\nNumber 2: %f", x[0], x[1]);

    return 0;
}

I am getting an error on these 2 lines

    *x[0] = num1;
    *x[1] = num2;

The error message is

Error: operand of ‘*’ must be a pointer

I don’t see what it is that is wrong. Does anyone see the problem?

EDIT: I changed the 2 lines to

    x[0] = num1;
    x[1] = num2;

and now I can run the program. However I get a new error after I enter the two numbers. The error message is:

  Unhandled exception at 0x40e00000 in arraysandpointers.exe: 0xC0000005: Access violation.
  • 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-05-26T17:26:29+00:00Added an answer on May 26, 2026 at 5:26 pm

    You don’t need the *. Just this is fine:

    x[0] = num1;
    x[1] = num2;
    

    In your original code x[0] already is of type float. *x[0] will try to deference it – which is not possible since x[0] isn’t a pointer. Therefore it doesn’t compile.

    EDIT : Also change your main to this:

    int main(){
    
        float x[2];
        get_nums(x);
    
        printf("Number 1: %f\nNumber 2: %f", x[0], x[1]);
    
        return 0;
    }
    

    It is not necessary to have the p_x. And it is what’s causing the crash.

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

Sidebar

Related Questions

So I'm trying to learn how to pass arrays through a function, so that
Trying to learn about php's arrays today. I have a set of arrays like
I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to
When a user is editing data in a form that is populated from a
I'm trying to learn more about arrays since I'm new to programming. So I
I am trying to learn to write OpenGL apps for the iPhone. How can
Trying to learn C++ and working through a simple exercise on arrays. Basically, I've
Here is a program I'm trying to run straight from section 1.9 of The
I'm trying to learn how I can get all of a user's pictures loaded
I'm trying to use scikit.learn which needs numpy/scipy arrays for input. The featureset generated

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.