Skip to main content

Posts

Showing posts with the label identifiers

Typedef Statement in C programming

   C supports a feature known as “type definition” that allows users to define an identifier that would represent an existing data type. The user-defined data type identifier can later be used to declare variables. It takes the general form: typedef type identifier ; Where type refers to an existing data type and identifier refers to the “new” name given to the data type. The existing data type may belong to any class of type, including the user defined ones. The new type is new only in name, but not the data type. typedef cannot create a new type. Some examples of type definition are: typedef int units ; typedef float marks ; Here, units represent int and marks represents float. They can be later used to declare variables as follows: units batch1, batch2 ; marks name1 [50] ; name2[50] ; batch1 and batch2 are declared as int variable and name1[50] and namer[50] are declared as 50 element floating point array variables. The main advantage of typedef ...

Identifiers in C programming

Identifiers are names that are given to various program elements, such as variables, functions and arrays. Identifiers consisted of letters and digits, in any order, except that first character must be a letter. Both upper and lower case letters are permitted, though common usage favors the use of lowercase letters for most type of identifiers. Upper and lowercase letters are not interchangeable (i.e. an uppercase letter is not equivalent to the corresponding lowercase letters). The underscore (  _ ) can also be included, and considered to be a letter. An underscore is often used in middle of an identifier. An identifier may also begin with an underscore. Rules for Identifier : 1. First character must be an alphabet (or Underscore). 2. Must consist of only letters, digits or underscore. 3. Only first 31 characters are significant. 4. Cannot use a keyword. 5. Must not contain white space. The following names are valid identifiers x     ...

C Tokens(C programming Basics)

In a passage of text, individual words and punctuation marks are called tokens. Similarly, in a C program the smallest individual units are also known as C tokens. C has six types of tokens: 1. Identifiers e.g. x area __ temperature PI 2. Keywords e.g. int float for while 3. Constants e.g. -15.5 100 4. Strings e.g. “ABC” “year” 5. Operators e.g. + - * 6. Special Symbols e.g. ( ) [ ] { }

C++ home work

Q1. How do you differentiate variables and identifiers? Answer: A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values at different times during execution. Identifiers refer to the names of variables, functions, arrays, classes, etc., created by the programmer. The first character in an identifier must be a letter or the _ (underscore) character; however, beginning identifiers with an underscore is considered poor programming style. Q2. Does C++ provide any ternary operator? If yes, explain its works. Answer: A ternary operator pair “? :” is available in C++ to construct conditional expressions of the form exp1 ? exp2 : exp3; Where,  exp1, exp2, andexp3are expressions. The operator ? : works as follows: exp1 is evaluated first. If it is nonzero (true), then the expression exp2 is evaluated and becomes the value of the expression. If exp1 is fa...