+ 2
Can we take input from user globally in c
If yes can u say me how it is possible
18 Respuestas
+ 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;
}
+ 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.
+ 2
K thanks for ur explanation
+ 2
Brian thaks for ur code
+ 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
+ 1
https://code.sololearn.com/cYc1bVa4U2FS/?ref=app
But the code is not working
+ 1
Can I know why it is not compiling
+ 1
Is there any way to do that in C
+ 1
~ swim ~ k thanks
+ 1
By the way,it has out put such as ....global input-0
https://code.sololearn.com/cMuf0v4QDyqi/?ref=app
+ 1
#include <stdio.h>
int sum=0;
int main()
{
int a;
scanf("%d",&a);
sum=a;
printf("%d",sum);
return 0;
}
+ 1
Mas Has thaks for the code
+ 1
Santosh kr Pathak thanks for the code
+ 1
Fro string you have to change
Int a;
By char name[];
And %d as %s
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;
}
0
Jayesh Sharma but it is not globally declared right
0
Dear friend you are correct but this aap is for global people so they can refer it
0
You may find answer in https://www.dummies.com/programming/c/basics-of-global-variables-in-c-programming/, and you may browse through https://www.codingunit.com/c-tutorial-functions-and-global-local-variables, https://www.google.com/search?, https://stackoverflow.com/questions/35744589/how-to-create-a-global-variable-using-user-input.