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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:45:10+00:00 2026-06-06T05:45:10+00:00

This morning in my CS lab, I was compiling and executing some C code.

  • 0

This morning in my CS lab, I was compiling and executing some C code. The code are as follow:

#include <stdio.h>
#define SIZE 3

int main()
{
float x[SIZE];
float *fp;
int i;

for(i=0; i<SIZE; i++)
//{
    x[i] = 0.5*(float)i;
//}

for(i-0; i<SIZE; i++)
//{ 
    printf(" %d %f \n", i, x[i]);
    
//}

fp=x;

for(i=0; i<SIZE; i++)
//{
    printf(" %d %f \n", i, *(fp+i));
//}  
}

This is the command I used in Ubuntu terminal to compile:

gcc -o program program.c

This is the command i used to execute

./program

This is the result I encountered:

0 0.50000

1 1.50000

2 2.50000

This the result I expected and found on other computers in the same lab.

0 0.50000

1 1.50000

2 2.50000

0 0.50000

1 1.50000

2 2.50000

Disclaimer: I double checked and triple checked the my code is entirely intact with ones in the other computers.

Clearly, something is wrong with the compiler here. Can anyone advise me what is the problem? And how to fix it?

Regards

  • 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-06T05:45:12+00:00Added an answer on June 6, 2026 at 5:45 am

    Your problem is:

    for(i-0; i<SIZE; i++)
       ^^^^^
    

    This makes the for-statement have no effect and hence the printf that follows gives no output
    If you compile it with strict warnings the compiler shall tell you so.

    Output:

    cc1: warnings being treated as errors
    prog.c: In function ‘main’:
    prog.c:15: error: statement with no effect

    Once you fix the obvious typo, all compilers will generate the output twice.

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

Sidebar

Related Questions

this morning I saw some strange code from one of my coworkers. In an
I was working on some template code this morning where I used a BOOST_STATIC_ASSERT
This morning we found an old chunk of code that was causing a library
So this morning I posted a confused question about assembly and I received some
this morning I came across this code, and I have absolutely no idea what
I was doing some reading on REST this morning and I came across the
Background While running benchmark tests this morning, my colleagues and I discovered some strange
This morning I discovered some strange behavior of the SmtpClient class (.net 3.5). Can't
This morning I accidentally saw the following snippet code, I was fairly surprised because
This morning, while trying to migrate some files from my test server to my

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.