473,387 Members | 1,283 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,387 software developers and data experts.

what the meaning of this code

sam
Hi,
I just want to ask the question about this code
int len =0; len =5;
"x41" * (len);
In this is "x41" is multiply by 5 or it just can acquire space like
this
x41x41x41x41x41 .

I am a newbie and i am confused , If you can't understand this
question i am sorry, but i just want the clarification of this code.
Sep 5 '08 #1
4 1435
On Sep 5, 12:20 pm, sam <sameer...@gmail.comwrote:
Hi,
I just want to ask the question about this code
int len =0; len =5;
"x41" * (len);
In this is "x41" is multiply by 5 or it just can acquire space like
this
x41x41x41x41x41 .

I am a newbie and i am confused , If you can't understand this
question i am sorry, but i just want the clarification of this code.
Hi,
You are trying to multiply an integer with a string, which has no
meaning. You will get a compilation error.

Rgds,
Sumanth
Sep 5 '08 #2
MiB
On 5 Sep., 13:20, sam <sameer...@gmail.comwrote:
Hi,
* * *I just want to ask the question about this code
int len =0; len =5;
*"x41" * (len);
*In this is "x41" is multiply by 5 or it just can acquire space like
this
x41x41x41x41x41 .

I am a newbie and i am confused , If you can't understand this
question i *am sorry, but i just want the clarification of this code.
The code you cite is not something you should waste your time with, it
seems to be part of an obfuscated program (intentionally written to be
hard to understand), or written by a real first-timer, or it may be
wrongly presented here.
int len = 0; len = 5;

This is identical to:
int len = 5;

The snippet:
"x41" * (len);

This is not valid in C++, you cannot multiply a const char array of
length 4 with an int. Old compilers for C and C++ may interpret this
as:
(int) "x41" * len;

This expression uses the memory address of the string constant "x41",
which may vary on each run of the program, and multiplies it with 5
(the content of the variable len). The round braces around len are
unneeded. Absent any instruction on what to do with the result of the
expression, it is then discarded - i.e. the whole line does nothing
and my be outright optimized away by the compiler. I assume there is
something missing in the code snippet you give.

best,

MiB.
Sep 5 '08 #3
sam 鍐欓亾:
Hi,
I just want to ask the question about this code
int len =0; len =5;
"x41" * (len);
In this is "x41" is multiply by 5 or it just can acquire space like
this
x41x41x41x41x41 .

I am a newbie and i am confused , If you can't understand this
question i am sorry, but i just want the clarification of this code.
well, i dont quite understand what you want to ask, nor what your code mean.

just from the code itself i thought:

"x41" is a const string, or, say the type is (char const *)

then the expression just got nothing meaningful.

Sep 5 '08 #4
On 9月5日, 下午7时20分, sam <sameer...@gmail.comwrote:
Hi,
I just want to ask the question about this code
int len =0; len =5;
"x41" * (len);
In this is "x41" is multiply by 5 or it just can acquire space like
this
x41x41x41x41x41 .

I am a newbie and i am confused , If you can't understand this
question i am sorry, but i just want the clarification of this code.
#include<iostream>
#include<string>
using namespace std;

string operator* ( string str,unsigned int times){
string tmp;
for( unsigned int i=0; i<times; i++) tmp+=str;
return tmp;
}

int main()
{
string str="hello,";
cout<<str*5<<endl;
return 0;
}
____________compiled by gcc 4.30_____
traxex # string_mul.exe
hello,hello,hello,hello,hello,
traxex #

Sep 6 '08 #5

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

Similar topics

12
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
20
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
7
by: KevinLee | last post by:
I found that the STL.NET published with VS Beta2, but what is the meaning of STL.NET. Is it just a simple wrapper to replace the old std stl? I can find nothing new but the keyword 'Generate' to...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
669
by: Xah Lee | last post by:
in March, i posted a essay 鈥淲hat is Expressiveness in a Computer Language鈥, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
132
by: Frederick Gotham | last post by:
If we look at a programming language such as C++: When an updated Standard comes out, everyone adopts it and abandons the previous one. It seems though that things aren't so clear-cut in the C...
17
by: Grizlyk | last post by:
Hello. What can be optimised in C++ code and how i can garantee stable behaviour below 1. Are expression "auto volatile" can deny removing as "unused temporary" like this: auto volatile...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
5
by: =?Utf-8?B?Sm9seW5pY2U=?= | last post by:
Hi everyone, I am learning c# and i don麓t understand a piece of code , can anyone explain the meaning of this code please. public class vector { public double? R = null; //I suppose this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.