Why show the program output error ? Where is the exact error ? I can't find | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why show the program output error ? Where is the exact error ? I can't find

#include<studio.h> #define a 10 int main (){ Const int a = 5; printf("a=%d\n",a); return 0; }

10th Sep 2020, 7:56 PM
Suparna Podder
Suparna Podder - avatar
4 Answers
+ 2
'a' is already defined as macro.. So const int a = 5; is error... [ stdio.h is correct; not studio.h]
10th Sep 2020, 8:02 PM
Jayakrishna 🇮🇳
+ 2
There is one syntexial error your const should be in small letters. This will give error becoz in macro you defined #define a 10 in program when you will print ( a) it will print 10 but in inner body of main you again defined value of (a) here value is overriding becoz in macro you already defined constant value and in inner part you trying to change value of a which is 5 so . If you change variable name of macro or const b=5 then it will work without error #include<stdio.h> #define a 10 int main (){ const int a = 5; printf("a=%d\n",a); return 0; }
11th Sep 2020, 1:26 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Jayakrishna🇮🇳 but l'm asking one thing suppose here l 'm put int a=5 then program showing what? Output 5 right?
10th Sep 2020, 8:14 PM
Suparna Podder
Suparna Podder - avatar
0
No. You can redefine 'a'. because it already defined as macro by #define a 10 It is a constant now.. Just you can use it only.. It is same as const int a = 10.. Again doing const int a =5 ; is error..
10th Sep 2020, 8:18 PM
Jayakrishna 🇮🇳