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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:18:13+00:00 2026-06-12T01:18:13+00:00

In the following code I am having the output like(last one giving segmentation fault)

  • 0

In the following code I am having the output like(last one giving segmentation fault)

 U   
 s    
 HelloThisisatest    
 Segmentation fault (core dumped)

but i do not understand why.
code is

int main()
{
   char *a[]={"Hello" "This" "is" "a" "test"};
   printf("%c\n",a[1][0]);
   printf("%c\n",a[0][8]);
   printf("%s\n",a[0]);
   printf("%s\n",a[3]);
   return 0;
}

Another question is that can we initialize an 2-D array without using comma?
Another situation that I got that when i am replacing the \ns by \ts then output changes like

“U s HelloThisisatest (null)”

why?

  • 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-12T01:18:14+00:00Added an answer on June 12, 2026 at 1:18 am

    This is because in C, two adjacent strings are concatenated into one. So “Hello” “World” is actually a single string “HelloWorld”.

    • In your case The array of pointer actually contains one single string “HelloThisisatest”. In the first printf you are accessing the location 1, which is undefined behaviour.

    • The next printf accesses the character 8 of the string which is s .

    • The third printf prints the entire string stored on the location 0, which is “HelloThisisatest”

    • The last printf attempts to access the array location 3, which is undefined behavour, as it is not initialized.

    EDIT

    Refer C11/C99 standard Section 5.1.1.2 Paragraph 6, which tells:

    Adjacent string literal tokens are concatenated.

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

Sidebar

Related Questions

I'm having some difficulty understanding why the output of the following code is not
I am having following code but unable to understand as to why no match
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
I am having following code for getting image from the web: NSURL *ImageURL =
I am having the following code: public ActionResult EditTrain(EditTraing editrain) { .... .... return
I m having the following code, however, I can see that the radio button
I'm having a problem with the following code foreach ($ex in (foo, bar, baz))
I'm having problems with the following code (I am a beginner in most things
I'm having troubles with the following code: <link type=text/css href=http://jqueryui.com/latest/themes/base/jquery.ui.all.css rel=stylesheet /> <script type=text/javascript
I'm having a problem with the following code snippet: <!DOCTYPE html> <html> <head> <title>Hangman</title>

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.