Frequently asked questions

  1. How do you declare a variable that will hold string values?

The char keyword can only hold 1 character value at a time. By creating an array of characters, you can store string values in it. Example: “char MyName[50]; ” declares a string variable named MyName that can hold a maximum of 50 characters.

  1. Can I use “int” data type to store the value 32768? Why?

No. “int” data type is capable of storing values from -32768 to 32767. To store 32768, you can use “long int” instead. You can also use “unsigned int”, assuming you don’t intend to store negative values.

  1. What are enumerated types?

Enumerated types allow the programmer to use more meaningful words as values to a variable. Each item in the enumerated type variable is actually associated with a numeric code. For example, one can create an enumerated type variable named DAYS whose values are Monday, Tuesday… Sunday. 

  1. What are the different data types in C?

The basic data types are int, char, and float. Int is used to declare variables that will be storing integer values. Float is used to store real numbers. Char can store individual character values.

  1. What is the use of a ‘\0’ character?

It is referred to as a terminating null character, and is used primarily to show the end of a string value.

  1. What is constant in C?

Constants refer to fixed values. They are also called as literals.

C constants are also like normal variables.

But, only difference is, constant values can’t be modified by the program once they are defined.

Constants may be belonging to any of the data type.

  1. What are the differences between exit() and return statement?

First difference is that exit() is a function while return is a statement.

Second difference is that exit() function terminates the program while return statement terminate the function.

Third difference is that exit() function always return some value where it is optional for return statement.

  1. What are the different types of variables in C?

There are three types of variables in C

  • Local variable
  • Global variable
  • Environment variable
  1. What is type casting?

Type casting is the process of converting the value of an expression to a particular data type.

Example:

int x,y;

C=(float) x/y;

Where x and y are defined as integers. Then the result of x/y is converted into float.

  1. What is the output of this C code?

#include  <stdio.h>

int main()

{

signed char chr;

chr = 128;

printf(“%d\n”, chr);

return 0;

}

Output:-128

 

  1. Comment on the output of this C code?

 

#include <stdio.h>

int main()

{

float f1 = 0.1;

if (f1 == 0.1f)

printf(“equal\n”);

else

printf(“not equal\n”);

}

OutPut:equal