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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:44:01+00:00 2026-06-08T03:44:01+00:00

I was just trying to test if I installed a new ide correctly and

  • 0

I was just trying to test if I installed a new ide correctly and tried to compile this basic program, both in the IDE and with gedit and GCC and it would compile, but crash after I launch the executable in the command line – I have no idea what’s wrong, as I’m still fairly new to pointers in C and it takes a while to wrap your head around the theory, according to most people.

Code:

#include <stdio.h>
#include <string.h>

    char print_func(char *hi);

    int main(void) {
        char *hi = "Hello, World!";
        print_func(*hi);
    }

    char print_func(char *hi) {
        printf("%d \n", *hi);
    }

I tried this:

#include <stdio.h>
#include <string.h>

char print_func(char *hi);

int main(void) {
    char *hi = "Hello, World!";
    print_func(&hi);
}

char print_func(char *hi) {
    printf("%d \n", *hi);
}

and it outputs 44 with no crash.

  • 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-08T03:44:02+00:00Added an answer on June 8, 2026 at 3:44 am

    If you do indirection using, print_func(*hi); you are passing a char and it is one byte. So when you are trying to read an integer, which is larger, an access violation occurs. You should call your function with a pointer print_func(hi). And if you want to print the address of a string, it is better to use %p in printf:

    printf("%p \n", hi); // print the address of hi
    

    If you want to print the first character in hi, use %c instead:

    printf("%c \n", *hi); // print first character of hi
    

    If you want to print the value of the first character in hi, use %d instead, with casting:

    printf("%d \n", (int)*hi); // print the value of the first character of hi
    

    To print the whole string use %s and pass the pointer:

    printf("%s \n", hi);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just installed new ubuntu vm to test around with node installed things in this
just trying to test for equality in this piece of code, but getting a
I am just trying to test out the new Zend Studio 7.2, and in
Right now I'm just trying to test my app on my phone and not
I was just trying to use Robotium in an Android JUnit Test, but the
I'm trying to create a very simple REST server. I just have a test
I have my new Liferay site ready and trying to test it in a
Just trying to get diff to work better for certain kinds of documents. With
Just trying to still get my head around IOC principles. Q1: Static Methods -
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas

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.