Question
What is the difference between these initializations?

char a[] = "string literal";
char *p = "string literal";

My program crashes if I try to assign a new value to p[i].

Answers

A string literal can be used in two slightly different ways. As an array initializer (as in the declaration of char a[]), it specifies the initial values of the characters in that array. Anywhere else, it turns into an unnamed, static array of characters, which may be stored in read-only memory, which is why you can't safely modify it. In an expression context, the array is converted at once to a pointer, as usual, so the second declaration initializes p to point to the
unnamed array's first element.

(For compiling old code, some compilers have a switch
controlling whether strings are writable or not.)   Your Comment




More Software Questions..
What is the inputsplit in map reduce software?

What is software configuration management?

What Is Java Api For Xml-based Rpc (jax-rpc)?

How can you implement fine-grained auditing?

What is IBM’s simple explanation for Big Data’s four critical features?

What is static synchronized method in JDBC API? Give an example?

What does the NULLIF function do?

What happens if a start method is not invoked and the run method is directly invoked?

Should we override finalize method

what is the difference between mysql_fetch_array and mysql_fetch_object?

How will XML affect my document links?

Why to use Style Sheets?

What are Filters in MVC?

Can you explain Application layer in OSI model?

How to define new testplan attributes?

What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?

Which oracle package is used to manage the oracle lock management services?

What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?

What is marker interface?

What types of partitioning are there for BW?



Search
Can you Answer!!
  • Q This is not the ground to impose restriction on Right of freedom of speech and expression
  • Q Who won the man of the series in Asia Cup T20?
  • Q What are the features of gwt?
  • Q What are the external factors affecting capital structure?
  • Q What is Maintenance Planning? What are different types of Maintenance Planning
  • Q In which palace mural paintings based on Kumarasambhava of Kalidasa can be seen?
  • Q Which of the following would be considered an essential feature of a network management system? A. A graphical interface to map the network topology B. Capacity to interact with the Internet to solve the problems C. Connectivity to a help desk for advice on difficult issues D. An export facility for piping data to spreadsheets
  • Q what is the difference between retest and regression testing?
  • Q If A driver drives a car four times a lap 10,20 30,60 kmph what is his average speed.
  • Q Diff b/n tracer & clipboard?
  • Q What are the methods available to determine molecular weight of polymer other than SDS PAGE, and MALDI MS?