I am studying for a C++ exam and the study guide says "Be able to initialize arrays using literal arrays." Ok then, so I think well yeah that is easy, a literal array is something like.....Wait, I have no idea what a literal array is! From what I can find (on the web) a "literal" is a constant and whose values are implied by their representations. I got that from this website: http://cpp.comsci.us/etymology/literals.html

This is still on clear to me, what is a literal? What is a literal array? What is the significance of a literal array? I would really like to be clear on this before I go in for my exam. Could someone please point me in the right direction.

Thanks,
Arielle

A literal is a string of characters inside quotes. For example char str[] = "Hello World"; In the above, "Hello World" is considered the literal.

ARGH! A literal string is just a C-String. Curse you silly vernacular! Thanks for the help Ancient, as always you are awesome.

It is not the string but the text inside the quotes. It could be either c or c++. cout << "Hello World\n"; That is also a literal.

So is a literal anything inside of quotation marks?

When using the term string literal, yes that is correct.

integers can also have literals. Example: int x = 123; In that the value 123 is a literal, sometimes called magic number or constant value.

> What is a literal array?
Edward's guess is that a literal array is supposed to be an initialization list:

int x[] = { 1, 2, 3, 4, 5 };

Can't a literal constant also be defined as const float pi = 3.14159265358979323?

Thank you all for your insight!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.