+ 2

Can we take input from user globally in c

If yes can u say me how it is possible

17th Apr 2020, 12:52 PM
Anuhya Anu
Anuhya Anu - avatar
23 Respostas
+ 4
Maybe you are thinking of a function pointer. This compiles without error in C, and on SoloLearn it prompts you for input without any reference to x in main(). Other compilers likely would optimize and remove matr_size() and x as unreachable/unused code. int (*x)()=&matr_size; int main() { //printf("%d", x()); return 0; }
17th Apr 2020, 3:55 PM
Brian
Brian - avatar
+ 4
Every code must be inside main function. If you mean this, int x; scanf ( x ); // is not allowed main() { printf (x); } it is not possible.
17th Apr 2020, 1:05 PM
Mustafa K.
Mustafa K. - avatar
+ 2
K thanks for ur explanation
17th Apr 2020, 1:49 PM
Anuhya Anu
Anuhya Anu - avatar
+ 2
Brian thaks for ur code
17th Apr 2020, 4:07 PM
Anuhya Anu
Anuhya Anu - avatar
+ 1
Can't we even take through pointers by using dynamic memory allocation I have seen this in some articles I haven't got the complete information there
17th Apr 2020, 1:11 PM
Anuhya Anu
Anuhya Anu - avatar
17th Apr 2020, 1:27 PM
Anuhya Anu
Anuhya Anu - avatar
+ 1
Can I know why it is not compiling
17th Apr 2020, 1:34 PM
Anuhya Anu
Anuhya Anu - avatar
+ 1
Is there any way to do that in C
17th Apr 2020, 1:50 PM
Anuhya Anu
Anuhya Anu - avatar
+ 1
~ swim ~ k thanks
17th Apr 2020, 2:01 PM
Anuhya Anu
Anuhya Anu - avatar
+ 1
By the way,it has out put such as ....global input-0 https://code.sololearn.com/cMuf0v4QDyqi/?ref=app
17th Apr 2020, 10:12 PM
Mas Has
Mas Has - avatar
+ 1
#include <stdio.h> int sum=0; int main() { int a; scanf("%d",&a); sum=a; printf("%d",sum); return 0; }
18th Apr 2020, 1:02 AM
Santosh kr Pathak
Santosh kr Pathak - avatar
+ 1
Mas Has thaks for the code
18th Apr 2020, 2:46 AM
Anuhya Anu
Anuhya Anu - avatar
+ 1
Santosh kr Pathak thanks for the code
18th Apr 2020, 2:46 AM
Anuhya Anu
Anuhya Anu - avatar
+ 1
Fro string you have to change Int a; By char name[]; And %d as %s
19th Apr 2020, 4:06 AM
Jayesh Sharma
Jayesh Sharma - avatar
0
Yes dear you can as you just uploade your codes on this aap. And type the following code #include<studio.h> Int main() { Int a Scanf("%d\n",&a); Printf ("you have enter the interger value a as %d\n",a); return 0; }
19th Apr 2020, 4:05 AM
Jayesh Sharma
Jayesh Sharma - avatar
0
Jayesh Sharma but it is not globally declared right
19th Apr 2020, 5:11 AM
Anuhya Anu
Anuhya Anu - avatar
0
Dear friend you are correct but this aap is for global people so they can refer it
19th Apr 2020, 5:16 AM
Jayesh Sharma
Jayesh Sharma - avatar