473,406 Members | 2,377 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,406 software developers and data experts.

Char type array

Hi there!

My problem consists in this:
When I define an array of char type like this:
char a[]={'a','aa','aaa'};
I get a lot of warnings like
warning C4305: 'initializing' : truncation from 'const int' to 'char'
I've tryed to define the size of it (char a[10] ) but I get same warnings
every time.
What's wrong with this?
Poz,
Sava

Jul 22 '05 #1
2 3200

"Sava Mikalački" <ba******@nspoint.net> wrote in message
news:br**********@neptun.beotel.net...
Hi there!

My problem consists in this:
When I define an array of char type like this:
char a[]={'a','aa','aaa'};
I get a lot of warnings like
warning C4305: 'initializing' : truncation from 'const int' to 'char'
I've tryed to define the size of it (char a[10] ) but I get same warnings
every time.
What's wrong with this?


char is a single charater. 'a' is a single character.
The constant 'aa' is an implementation defined int consant.
It is NOT a string literal. A string literal would be "".

char a[] is an array of (with this initialization) 3 characters.
It is not an array of strings.

If you want strings, do this:

#include <string>
std::string a[] = { "a", "aa", "aaa" };
Jul 22 '05 #2
Sava Mikalački wrote:
...
My problem consists in this:
When I define an array of char type like this:
char a[]={'a','aa','aaa'};
I get a lot of warnings like
warning C4305: 'initializing' : truncation from 'const int' to 'char'
I've tryed to define the size of it (char a[10] ) but I get same warnings
every time.
What's wrong with this?
...


In C/C++ 'aa' and 'aaa' are integer constants. The compiler already
explained the rest. You are trying to initialize members of 'char' array
with these constants, which results in truncation.

There's no way to say what else is wrong with this until you explain
what is that you are trying to do.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3

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

Similar topics

35
by: Ying Yang | last post by:
Hi, whats the difference between: char* a = new char; char* b = new char; char c ;
10
by: techie | last post by:
I'm creating a class BookType that will store information about books. Each book type can have up to 4 authors. I defined a new type for an array of char: typedef char array4_t; This will...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
3
by: s.subbarayan | last post by:
Dear all, I encountered the following piece of program: #include <stdio.h> void strprint(char *str); void main() { char *spr="hello"; strprint(spr); }
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
13
by: chellappa | last post by:
hi , please explain me , char pointer , char Array, char ,string... i have some many confussion about this... please clarify to me.. i need some example about this program by chellappa.ns
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
21
by: arnuld | last post by:
int main() { const char* arr = {"bjarne", "stroustrup", "c++"}; char* parr = &arr; } this gives an error: $ g++ test.cpp test.cpp: In function 'int main()': test.cpp:4: error: cannot...
16
by: MN | last post by:
I have a question : How to understand the mean of char** type ?
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...

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.