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

When can a far pointer be used?

0 Answers  


can we initialize all the members of union?

2 Answers  


what is volatile in c language?

9 Answers   Cap Gemini, HCL, Honeywell, TCS, Tech Mahindra,


How do I create a directory? How do I remove a directory (and its contents)?

0 Answers  


A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles

0 Answers  


What is structure pointer in c?

0 Answers  


Hi Every one...........I have been selected for the SBI Clerk. But i m one month Pregnanat. So anyone please suggest me, is they take any objection on my joining .

4 Answers   State Bank Of India SBI,


pierrot's divisor program using c or c++ code

0 Answers  


Do you know what are the properties of union in c?

0 Answers  


array contains zeros and ones as elements.we need to bring zeros one side and one other side in single parse. ex:a[]={0,0,1,0,1,1,0,0} o/p={0,0,0,0,0,1,1,1}

12 Answers   Google, Motorola,


how to connect oracle in C/C++.

3 Answers   TCS, Wipro,


write a programe returns the number of times the character appears in the string

2 Answers  


Categories