473,976 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

char * ptr = "amit", in which area of memory it is stored (heap,stack,cod e,global)

char *str1="amit";
char str2[]="mehta"
strcat(str1,str 2);

It will crash, I feel str1 will be stored in code section. Once memory
is allocated, you cannot change or append into this.

Please correct me If I am wrong..

Nov 15 '05
10 1966
CoL wrote:
In this case ,
In what case? Quote context please. To quote from one of the MANY posts
where this problem and the solution has been stated:

| "If you want to post a followup via groups.google.c om, don't use
| the broken "Reply" link at the bottom of the article. Click on "show
| options" at the top of the article, then click on the "Reply" at the
| bottom of the article headers." - Keith Thompson
|
| Your post needs to be able to stand on its own, you shouldn't assume
| that everyone just finished reading the post you are replying to
| before reading yours. Usenet is not an incredibly reliable medium and
| it is often the case that followups, such as yours, make it to a news
| server before the post you are responding to. It is also not rare for
| news readers to screw up the order of posts and followups, Google
| Groups has a number of problems in this area. If you include context,
| these things become non-issues.
according to ANSI C standard the string literal becomes
the part of read only memory,
Not quite, none of the ANSI or ISO C standard require read only memory.
most obvious the datasection. So the
nature of the char * str actually becomes const char *str1... so you
cant write into it.


I'm not sure exactly what you are trying to say, and so I suspect you
have not quite understood the situation.

int main(void)
{
char *ptr="string literal";
*ptr=0;
}
Is syntactically perfectly legal and no compiler is *required* to
complain about it. However, since the standard states that attempting to
modify a string literal is undefined behaviour *anything* can happen if
you run it. The most common things are the program crashing (if the
compiler chooses to place "string literal" in read only memory) andall
string literals ending in "string literal" including the one that says
"This is a string leteral" being affected.

So you are correct if you think that a program is "not allowed" to
modify a string literal, but not if you thing the compiler is required
to complain or if you think the program is guaranteed to crash in a
visible way.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4412
by: Dmitri | last post by:
Hi there, Does anybody know what is DB2 UDB admin API equivalent to "db2 terminate" command? Some background: I'm developing monitoring application(http://chuzhoi_files.tripod.com). I want to be able to specify a node number during attachment, so I'm using sqlesetc (API for "set client attach_dbpartitionum" command). If user specifies an incorrect node number, DB2 will fail with something like:
10
3533
by: Amit | last post by:
Which is more efficient and why? p++ or ++p. Thanks.
8
14798
by: John | last post by:
Hi all: Is there a C function to make a procedure sleep or delay for a few seconds/minutes on Linux and Sun OS platform? Thanks
7
3017
by: kaul | last post by:
i want to create a 2-d array containg r rows and c columns by dynamic memory allocation in a single statement so that i will be able to access the ith and jth index as say arr how is that possible?
2
1758
by: Ashish | last post by:
Iam trying the out of state session management for the first time, trying to convert a big project to be adaptable to both type of session management .. what i see that it is trying to serialize a class which is not touched by session object, do i have to serialize all the classes in the project or only the ones touches, also the abstract classes ? TIA -ashish
3
4586
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function Session_Start() { Session.Timeout = 3000; } in global.asax
13
2847
by: andro | last post by:
Hi everybody! I have several tables from which I want to exract the SAME value (along with other referenced data). All the values are in the same column within the tables. How can I achieve this? TIA. Andro
13
2104
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Pair { std::string name;
6
1812
by: Amit_Basnak | last post by:
Dear Friends I have two structures as below typedef struct { long_int length; char data; } CI_STRUCT_DATA; typedef CI_STRUCT_DATA *ptr_CiStructData;
0
10171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11819
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11408
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10084
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5153
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.