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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:10:58+00:00 2026-06-17T12:10:58+00:00

I am trying to learn C but I get an error in the following

  • 0

I am trying to learn C but I get an error in the following code.

If I use radius in volume I get an error: error #2069: Initializer must be constant.

#include <stdio.h>
#define PI (3.14)

/* Define radius*/
int radius = 10;
float volume = ( 4.0f / (3.0f * PI * radius) );

int main(void){

return 0;
}

But when I change radius with an actual number, it compiles just fine.

#include <stdio.h>
#define PI (3.14)

/* Define radius*/
int radius = 10;
float volume = ( 4.0f / (3.0f * PI * 10) );

int main(void){

    return 0;
}

Why does this happen, and what can I do to make the first version work?

  • 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-17T12:10:59+00:00Added an answer on June 17, 2026 at 12:10 pm

    In C you cannot initialize global variables with non-constant expressions.

    C99 Standard: Section 6.7.8:

    All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.

    In your example, volume is a global variable with static storage duration and radius is not a constant. Hence the error.

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

Sidebar

Related Questions

I'm trying to learn JavaScript, but the following code has been giving me a
I'm trying to learn GUI programming using python2 and GTKBuilder, but I get a
Hello I'm trying to learn ruby blocks. But I have a trouble to get
i'm trying to learn codeigniter (following a book) but don't understand why the web
I'm trying to learn C++ currently, but I'm having issues with the code below.
I'm trying to learn how to use the library vcglib (http://vcg.sourceforge.net/index.php/Main_Page) but I'm having
I'm trying to learn SVG for the first time but the code seems to
I'm trying to learn how to use custom events in Flex. I'm following Oliver
I'm trying to learn some Rails but I seem to get stuck on this
I am trying to learn to use mercurial by pushing onto Google code. I

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.