473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Beginner question

I am having a basic question..How do (Right to left or left to right) compiler process the assignment statement in C

Ex: int i = 5

I feel compiler will create memory for storing variable if type ' int ' of name 'a' and assign 5 to it. That is it from left to right.

Is my understanding is correct or not ?

2. How about the following case

char *p = "aabbcc"
char *q = "aabbcc"

I heard in the second case compiler will search for "aabbcc" string and assign pointer to that one. so in this case both will point to the one constant string named '"aabbcc"
Is my understanding is correct?
Sep 1 '06 #1
3 1543
godsent
33
int i= 5 means that u are declaring a variable i with datatype integer..n u r assigning 5 to i..
Sep 1 '06 #2
rgb
37
char *p = "aabbcc";
char *q = "aabbcc";

there will be 2 pointers here, both will have the same value (as per assignment statement) but not the same address space (not point on one constant string)

you can test this by assigning a different value on any of the two pointer and showing the content of the pointer using [printf("%s",p);]
Sep 1 '06 #3
Banfa
9,065 Expert Mod 8TB
char *p = "aabbcc";
char *q = "aabbcc";

there will be 2 pointers here, both will have the same value (as per assignment statement) but not the same address space (not point on one constant string)

you can test this by assigning a different value on any of the two pointer and showing the content of the pointer using [printf("%s",p);]
Actually the pointers will have different values, what the point to will be the same data but just because the 2 strings given are the same.

However, although it is quite unusual, a few compilers (mainly on embedded platforms) will actually assign the pointers the same value. This is because some platforms give string constants the type const char so the data pointed to can not be changed and would be stored in ROM. making the pointers point to the same(constant) thing saves space. However in such a case these lines would (should) produce a warning or error because you would be trying to assign a const char * to a char *.

I have to say that although I know things like this exist in theory I have never used a compiler that did this.
Sep 1 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Svens | last post by:
Hey everyone! I'm a math student working on a short script involving logs. I have a function on my scientific calculator, and was wondering if there was a similar funtion in python. For example:...
3
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
14
by: z_learning_tester | last post by:
But I can't seem to find the answer. The question is how do you reverse the words in a string? Or how do you reverse the numbers listed in a string? The example is usually something like: Turn...
12
by: Blaze | last post by:
I am doing the first walk through on the Visual Studio .Net walkthrough book to learn a little about programming. I am having issues with the first tutorial not running correctly. It seems that...
5
by: optimistx | last post by:
As a beginner in javascript I had a question. I was reading FAQ and posts here. I became very unhappy: Obviously this group is mainly for wise, pedantic, unkind etc people, who already know...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
4
by: a | last post by:
Dear all vb.net developer I want to know the time I need to master vb.net? I'm beginner
3
by: Ben Keshet | last post by:
I have a probably simple beginner's question - I have a script that I am currently able to print its output. instead, i want to write it into a file - I tried different versions of write() but...
2
by: roanhn | last post by:
Hello. I've to to write a master's thesis. Currently I deal with php, mysql, ajax. Fate decreed that I've to choose one of this subjects: 1.gdi+ library in .net technology 2.ado.net technology...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.