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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:57:30+00:00 2026-05-31T05:57:30+00:00

I am very new to C Programming and have a doubt… I’ve been asked

  • 0

I am very new to C Programming and have a doubt… I’ve been asked to find errors in certain segments of C code… and this segment has me a bit confused so would appreciate the help…

int main(void)     
{
    int myInt = 5;
    printf("myInt = %d");
    return 0;
}

As far as i understand there is nothing wrong in this code. What i wanna know is why is this statement printing out a random number ??

The output i get is

myInt = 1252057154

Would appreciate the help… Thanks

  • 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-31T05:57:32+00:00Added an answer on May 31, 2026 at 5:57 am

    You should read more about C programming.

    And you should enable all warnings and debugging when compiling. With GCC, this means gcc -Wall -Wextra -g (on Linux at least).

    When compiling with

    gcc -Wall -Wextra -g john.c -o john
    

    I am getting the following warnings:

    john.c: In function ‘main’:
    john.c:4:5: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
    john.c:4:5: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
    john.c:4:5: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat]
    john.c:3:9: warning: unused variable ‘myInt’ [-Wunused-variable]
    

    So the correction is simple:

    /* file john.c */
    #include <stdio.h>
    int main(void)     
    {
      int myInt = 5;
      printf("myInt = %d\n", myInt);
      return 0;
    }
    

    which gets compiled without warnings.

    Notice the \n at the end of printf format string. It is important.

    Always enable all the warnings the compiler can give you and trust the compiler, so correct your code till no warnings is given.

    And learn to use the debugger (e.g. gdb on Linux).

    The behavior you observed is undefined behavior; anything could happen with a standard conforming implementation of C (even an explosion).

    Happy hacking.

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

Sidebar

Related Questions

I'm very much new to programming and have been doing fairly well so far.
I'm very new to IOS programming and i have doubt with NSThread. My problem
I am very new to programming, and have been banging my head against the
I am very new to iOS Programming and have been learning for only a
I'm very new to programming in Android, but have been struggling all day with
I'm very new to programming and have followed this screencast at emersonlackey.com on adding
Hey I am very new to Web Programming. I have been learning PHP from
I am very new at all this c# Windows Phone programming, so this is
I am very new to programming in FLEX. I have inherited a FLEX 4
I am very new to programming, so I apologize if this question seems absurdly

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.