Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Today my friend attend an interview , in that he was failed to ans a question. The question was like this Program to find the datatype of a given Input He asked me and I was able to crack up to this


Objective-C
include<stdio.h> 
main() 
{ 
  char n; 
  printf("\nEnter a character: "); 
  scanf("%c",&n); 
  if(isdigit(n)) 
     printf("\nInteger"); 
  else 
     printf("\nCharacter"); 
}



But it will tell only integer or charector, how about for an inputs like float double. Can any one help me inthis. Here we can use any programming language.
Posted

1 solution

Generally speaking, a character cannot represent an integer number. It can just represent a digit (you know an integer is a sequence of one or more digits, possibly prefixed by the sign).
Even more so, a single character cannot represent a float or a double.
In order to tell the type of a value represented by a string, your need to write a lexer (see "Lexical analysis" at Wikipedia[^]).
 
Share this answer
 
Comments
baliram bhande 23-Apr-14 11:34am    
you can check each term according you have check above you are program you will get result.
[no name] 27-Apr-14 16:57pm    
For java every input and output is string.<br>
So programmer should explicitly convert(type cating) data according to their need.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900