Access over 20 million homework & study documents

search

6 1 (a) The C programming language distinguishes character constants

Content type
User Generated
Rating
Showing Page:
1/3
6.1 (a) The C programming language distinguishes
character constants from string constants by
using single quotation marks for characters and double
quotation marks for strings. Thus,
\'c\' is the character c, while \"c\" is a string of length 1
consisting of the single character c.
Why do you think this distinction is made? Is it useful?
(b) Python, on the other hand, uses double quotation
marks for both characters and strings
(thus, \"c\" is either a character or string, depending on
context). Discuss the advantages and
disadvantages of these two approaches.
6.3 Discuss the pros and cons of ignoring or requiring
white space (i.e., blanks, end-of-lines, and
tabs) when recognizing tokens.
6.4 Many programming languages (like C) do not allow
nested comments. Why is this requirement
made? Modula-2 and a few other languages do allow
nested comments. Why is this useful?
6.5 (a) Describe the strings that are represented by the
regular expression:
[0-9]+((E|e)(\\+|\\-)?[0-9]+)?
(b) Write a regular expression for C identifiers consisting
of letters, digits, and the underscore
character _, and starting with a letter or underscore.
Solution
6.1 a) This is design decision, it is useful to clearly identify

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
for compiler which one is string and char and act
accordingly in terms of memory allocation, operations.
6.1 b) Advantage of having single quotes for both is
programmer doesn\'t need to remember which one to use
for which and get rid of confusion but the disadavntage is
there is no distinctionh and for later point either they have
to cleraly specify (comment) which is char and which is
string.In case that a huge program and memebers were
defined two three days back and programmer foget to
comment then it may lead to appying wrong operations.
6.3v Prons :
1) It becomes easy copy code to different levels (the
programmer has no need to fix the indentation)
2) It is moreconsistent as some of the editors display
whitespace differently.
Cons :
1) It doesn\'t help in reducing inconsistent indentation in
code.
6.4 To ease parsing as if nested comments are not allowed
then compiler doesn\'t have to maintian a stack.
In some languages nested comments are allowed so that a
section of code could be commented out even if it conatins
other comments.
6.5 a) This regular expression defines the scientific

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
6.1 (a) The C programming language distinguishes character constants from string constants by using single quotation marks for characters and double quotation marks for strings. Thus, \'c\' is the character c, while \"c\" is a string of length 1 consisting of the single character c. Why do you think this distinction is made? Is it useful? (b) Python, on the other hand, uses double quotation marks for both characters and strings (thus, \"c\" is either a character or string, depending on context). Discuss the advantages and disadvantages of these two approaches. 6.3 Discuss the pros and cons of ignoring or requiring “white space” (i.e., blanks, end-of-lines, and tabs) when recognizing tokens. 6.4 Many programming languages (like C) do not allow nested comments. Why is this requirement made? Modula-2 and a few other languages do allow nested comments. Why is this useful? 6.5 (a) Describ ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Just the thing I needed, saved me a lot of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Documents