Questions tagged [literals]

a notation for representing fixed values in source code

External links

1554 questions
83
votes
4 answers

Make C floating point literals float (rather than double)

It is well known that in C, floating point literals (e.g. 1.23) have type double. As a consequence, any calculation that involves them is promoted to double. I'm working on an embedded real-time system that has a floating point unit that supports…
Zeus
  • 1,052
  • 1
  • 9
  • 18
81
votes
10 answers

Addresses of two char pointers to different string literals are same

#include #include int main() { char * p = "abc"; char * p1 = "abc"; printf("%d %d", p, p1); } When I print the values of the two pointers, it is printing the same address. Why?
seereddi sekhar
  • 881
  • 9
  • 20
80
votes
2 answers

Does Kotlin have a syntax for Map literals?

In JavaScript: {foo: bar, biz: qux}. In Ruby: {foo => bar, biz => qux}. In Java: HashMap map = new HashMap<>(); map.put(foo, bar); map.put(biz, qux); Surely Kotlin can do better than Java?
Thomas
  • 174,939
  • 50
  • 355
  • 478
80
votes
2 answers

How to specify const array in global scope in Rust?

When I tried to add a const array in the global scope using this code: static NUMBERS: [i32] = [1, 2, 3, 4, 5]; I got the following error: error: mismatched types: expected `[i32]`, found `[i32; 5]` (expected slice, found array of 5…
Oleg Eterevsky
  • 1,484
  • 2
  • 12
  • 14
79
votes
5 answers

Why are string literals l-value while all other literals are r-value?

C++03 5.1 Primary expressions §2 says: A literal is a primary expression. Its type depends on its form (2.13). A string literal is an lvalue; all other literals are rvalues. Similarly, C99 6.5.1 §4 says: A string literal is a primary expression.…
Alok Save
  • 202,538
  • 53
  • 430
  • 533
73
votes
4 answers

What is array literal notation in javascript and when should you use it?

JSLint is giving me this error: Problem at line 11 character 33: Use the array literal notation []. var myArray = new Array(); What is array literal notation and why does it want me to use it instead? It shows here that new Array(); should work…
Matt
  • 5,547
  • 23
  • 82
  • 121
71
votes
3 answers

Purpose of Scala's Symbol?

Possible Duplicate: What are some example use cases for symbol literals in Scala? What's the purpose of Symbol and why does it deserve some special literal syntax e. g. 'FooSymbol?
soc
  • 27,983
  • 20
  • 111
  • 215
69
votes
8 answers

How to make eclipse "File Search" to also search inside source jars containing some text?

I am working on a (Java) project in which I have many jars which have a source-jar file attached. Is there any way to make the eclipse "File Search" search for Java files (and txt, xml etc. for that matter) containing some string literal inside…
akjain
  • 1,787
  • 3
  • 20
  • 35
68
votes
10 answers

PHP object literal

In PHP, I can specify array literals quite easily: array( array("name" => "John", "hobby" => "hiking"), array("name" => "Jane", "hobby" => "dancing"), ... ) But what if I want array of objects? How can I specify object literal in…
Tomas
  • 57,621
  • 49
  • 238
  • 373
66
votes
6 answers

What does the @ prefix do on string literals in C#

I read some C# article to combine a path using Path.Combine(part1,part2). It uses the following: string part1 = @"c:\temp"; string part2 = @"assembly.txt"; May I know what is the use of @ in part1 and part2?
Vaibhav Jain
  • 33,887
  • 46
  • 110
  • 163
66
votes
2 answers

Which C# XML documentation comment tag is used for 'true', 'false' and 'null'?

Which C# XML documentation comment tag is used for the literals true, false and null? In Microsoft's own documentation, these literals appear in bold text. For example, the documentation for the property ArrayList.IsFixedSize appears as: true if…
DavidRR
  • 18,291
  • 25
  • 109
  • 191
65
votes
5 answers

How to set bool pointer to true in struct literal?

I have the function below which accepts a bool pointer. I'm wondering if there is any notation which allows me to set the value of the is field to true in the struct literal; basically without to define a new identifier (i.e. var x := true ;…
The user with no hat
  • 10,166
  • 20
  • 57
  • 80
63
votes
6 answers

When did C++ compilers start considering more than two hex digits in string literal character escapes?

I've got a (generated) literal string in C++ that may contain characters that need to be escaped using the \x notation. For example: char foo[] = "\xABEcho"; However, g++ (version 4.1.2 if it matters) throws an error: test.cpp:1: error: hex escape…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
63
votes
10 answers

What is a class literal in Java?

From the Java tutorial: Finally, there's also a special kind of literal called a class literal, formed by taking a type name and appending ".class"; for example, String.class. This refers to the object (of type Class) that represents the type…
gameover
  • 11,813
  • 16
  • 59
  • 70
62
votes
6 answers

Is 0 an octal or a decimal in C?

I have read this. It's octal in C++ and decimal in Java. But no description about C? Is it going to make any difference if 0 is octal or decimal? This is the question asked by my interviewer. I said no and I explained that it is always 0 regardless…
Gibbs
  • 21,904
  • 13
  • 74
  • 138