char s[10]="welcome";
Here for example &s is of type char(*)[2].
Is there anyway in C to find the type of a variable like this?
Most* compilers support the typeof operator, which can be quite handy. It is essentially equivalent to C++'s decltype, so you'd probably need a macro to turn it into something useful, like a string:
#define _STRINGIFY(arg) #arg
#define STRINGIFY(arg) _STRINGIFY(arg)
*: most compilers being clang, GCC, and I believe MSVC.
The compiler knows but that information is discarded when the compilation is complete. You cannot somehow ask at runtime for the textual description of what type of variable it is. There is no method that will return the string "char(*)[2]"
To do this, you would have to either integrate with a C compiler or write a C compiler and run your code through it at runtime.
typeof.
sisn't long enough to hold the string"welcome".