in Programming in C
5,904 views
0 votes
0 votes
4. Which of the following is not a valid variable name declaration and why?
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14
in Programming in C
5.9k views

3 Answers

1 vote
1 vote

Variable Definition in C

A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type and contains a list of one or more variables of that type as follows −

type variable_list;

Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object; and variable_list may consist of one or more identifier names separated by commas. Some valid declarations are shown here −

int    i, j, k;
char   c, ch;
float  f, salary;
double d;

This is all about basics which is required to solve your question.

All the 4 declarations that u have given is perfect But One thing when u go print tha value of PI , u have to use proper format specifier 

like: for int  -  u have to use '%d'

      for float  -  u have to use "%f"

      for double - "%d"

---------------------------------------------------------------------------

#define PI 3.14: this is macro definition i think. So when we want to print 3.14 in place of PI then we have to use format specifier " %f "...

1 comment

i want to ask sir that i think "#define PI 3.14" declaration  is write dose not matter we use this variable in program or not.

   sir you should read the question not take this question in the direction of input/output sorry for that i was writing  heading input/output.
0
0
0 votes
0 votes
I think d because #define is textual substitution.

1 comment

when i was running this code "#define PI 3.14" this was not give any error.
0
0
0 votes
0 votes
d option

because it require formate specifiers like %f %d %l for vlaue but other options have valid type define

Related questions