Ubuntu Blog – Latest informations

Just another WordPress.com site

C: diff between char* a and char s[]

Name Remember Me? Password
Forgot Password?  Programming / Scripting   Request help with C/C++, Perl, PHP, Python, Ruby, Bash Scripts, or other Linux programming/scripting related issues
Site Navigation Linux Forums Linux Articles Product Showcase Linux Downloads Linux Hosting Free Magazines Job Board IRC Chat RSS Feeds Free Publications

Linux Forum Topics Linux Forums Linux Forums Site News Your Distro Arch LinuxDebian LinuxGentoo LinuxKnoppix LinuxMandriva LinuxMEPIS LinuxMint LinuxPCLinuxOSSlackware LinuxSuSE LinuxRed Hat / Fedora LinuxUbuntu LinuxOther Linux DistributionsEverything BSD Linux Resources Linux Tutorials, HOWTO’s & Reference Material GNU Linux Zone NewbieInstallationApplicationsHardware / PeripheralsDesktop / X-WindowsGaming / Multimedia / EntertainmentLaptops / Netbooks / MinibooksMobile DevicesWireless InternetNetworkingServersKernelProgramming / ScriptingGraphic Arts / Digital ImagingSecurityMiscellaneousWine The Community The Coffee LoungeComments / Feedback / Suggestions Reply   Thread Tools Display Modes Old1 Hour Ago  #1 (permalink) madhuti Just Joined!  
Join Date: May 2009 Posts: 18 Hello,

int main(void) {
char s[] = “Hello”; // here the data will be stored in stack
char* ss = “Hello”; // Can u tell me where this data will be stored in process
// memory layout
ss[0] = ‘a’; // gives segmentation fault, why

Thanks in advance
Madhu madhuti is offline 

Reply With Quote Old50 Minutes Ago  #2 (permalink) gerard4143 Linux Enthusiast  
gerard4143's Avatar  
Join Date: Dec 2007 Location: Canada, Prince Edward Island Posts: 695 Its stored in read only memory. __________________
Make mine Arch Linux gerard4143 is online now  Reply With Quote Old23 Minutes Ago  #3 (permalink) madhuti Just Joined!  
Join Date: May 2009 Posts: 18 Reg: Then what is the difference between the below two statements

const char* p = (char*) malloc(50);
p[0] = ‘a’; // This will gives a compilation error

const char pp[] = “Hello”;
pp[0] = ‘a’; // This will gives a compilation error

char* s = “Hello”;
s[0] = ‘a’; // this gives a runtime error segmentation fault.

Thanks in advance,
Madhu madhuti is offline  Reply With Quote Old3 Minutes Ago  #4 (permalink) gerard4143 Linux Enthusiast  
gerard4143's Avatar  
Join Date: Dec 2007 Location: Canada, Prince Edward Island Posts: 695 Number one its three statements not two. If your curious about programming at this level you should get a good tutorial on the debugger and familiarize yourself with bin utilities like objdump. __________________
Make mine Arch Linux gerard4143 is online now  Reply With Quote Reply
« Previous Thread|Next Thread »
Currently Active Users Viewing This Thread: 4 (1 members and 3 guests) gerard4143 Thread Tools Show Printable Version Show Printable Version Email this Page Email this Page Display Modes Linear Mode Linear Mode Hybrid Mode Switch to Hybrid Mode Threaded Mode Switch to Threaded Mode
Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are Off Refbacks are Off
Free Magazines Implementing Detailed User-Level Auditing of UNIX & Linux Systems
Enhance regulatory compliance and troubleshooting through detailed auditing, logging and real-time monitoring of UNIX/Linux user activity.
subscribe Linux from Scratch – Receive Your Complimentary eBook NOW!
Linux from Scratch describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using nothing but the source code of software that you need.
subscribe A Complete Beginner’s Manual for Ubuntu 10.04 (Lucid Lynx)
Getting Started with Ubuntu 10.04 (Lucid Lynx) is a comprehensive beginners guide for the Ubuntu operating system; it features comprehensive guides, How Tos and information on anything you need to know after first installing Ubuntu.
subscribe The Incredible Guide to NEW Ubuntu (Karmic Koala)
There are a lot of people still stuck with Windows because it’s the �easier alternative’. Linux is both cheaper and more versatile than Microsoft’s operating system, but the learning curve has frightened off many people.
subscribe The GNU/Linux Advanced Administration
The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.
subscribe A Newbie’s Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you’re a complete Linux newbie and looking for a quick and easy guide to get you started this is it.
subscribe Run Your Own Web Server Using Linux & Apache – Free 191 Page Preview
Learn about everything you’ll need to build and maintain your Linux servers, and to deploy Web applications to them.

All times are GMT. The time now is 12:28 PM.

Advertise About Us Contact Us Write For Us Archive Top All Areas Articles Downloads Forums Linux Hosting © 2000 – – All Rights Reserved – Property of  MAS Media
Content Relevant URLs by vBSEO 3.3.1


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


This entry was posted on October 12, 2010 by and tagged , .
%d bloggers like this: