can we declare a variable in different scopes with different
data types? answer in detail

Answers were Sorted based on User's Feedback



can we declare a variable in different scopes with different data types? answer in detail..

Answer / rajasekhar

yes we can declare the same variable with different data types in different scopes...


y bcoz as the scope ends the availability of that particular variable also ends..

so, if u create a variable which is declared in the another scope there will be no error...


ex: void main()
{
int a;
}/*the availability of a has ended here*/
int print()
{
char a;

return 0;
}/* as this is next scope, the variabla declared in the main function does not affect this function*/


hope u understood



thank u

Is This Answer Correct ?    7 Yes 0 No

can we declare a variable in different scopes with different data types? answer in detail..

Answer / tatukula

Yes,
why because that variable scope is ends with in that block only...

int main()
{
int a=20;
printf("%d\n",a);

{
char a='c';
printf("%c\n",a);
}
printf("%d\n",a);
}

output: 20 c 20

Is This Answer Correct ?    0 Yes 0 No

can we declare a variable in different scopes with different data types? answer in detail..

Answer / palani222samy

ya we can declare, ex: int array b[],
char array c[]

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

prog for 1st five prime numbers in 2^x - 1

0 Answers  


When you call malloc() to allocate memory for a local pointer, do you have to explicitly free() it?

2 Answers   Aloha Technology,


code for copying two strings with out strcpy() function.

6 Answers  


In a switch statement, what will happen if a break statement is omitted?

0 Answers  


wat is the output int main() { char s1[]="Hello"; char s2[]="Hello"; if(s1==s2) printf("Same"); else printf("Diff"); }

3 Answers  






Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

0 Answers  


Differentiate call by value and call by reference?

0 Answers   Cyient,


What is 1d array in c?

0 Answers  


Explain what are preprocessor directives?

0 Answers  


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

0 Answers  


An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode

0 Answers  


What are the advantages and disadvantages of c language?

0 Answers  


Categories