250+ TOP MCQs on Character Class Testing & Conversions and Answers

’s Technical Questions and Answers on C helps people preparing for Job Interviews. One should practice these questions continuously for 2-3 months, thereby ensuring a top position in Technical rounds in C Programming language.

Here is a listing of C Objective Questions on “Character Class Testing & Conversions” along with answers, explanations and/or solutions:

1. Which is true about isaplpha(c), where c is an int that can be represented as an unsigned?

char or EOF.isalpha(c) returns

a) Non-zero if c is alphabetic
b) 0 if c is not alphabetic
c) Both Non-zero if c is alphabetic & 0 if c is not alphabetic
d) None of the mentioned
Answer: c
Clarification: None.

2. Which is true about isupper(c), where c is an int that can be represented as an unsigned?

char or EOF.isupper(c) returns

a) Non-zero if c is upper case
b) 0 if c is not upper case
c) Nothing
d) Both Non-zero if c is upper case & 0 if c is not upper case
Answer: d
Clarification: None.

3. Which is true about isalnum(c), where c is an int that can be represented as an unsigned?

 char or EOF.isalnum(c) returns

a) Non-zero if isalpha(c) or isdigit(c)
b) 0 if not isalpha(c) or not isdigit(c)
c) Both Non-zero if isalpha(c) or isdigit(c) & 0 if not isalpha(c) or not isdigit(c)
d) None of the mentioned
Answer: c
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char c = 't';
  6.         printf("%dn", isspace(c));
  7.     }

a) Non-zero number
b) Nothing
c) Error
d) t
Answer: a
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char c = 't';
  6.         printf("is :%cn", tolower('A'));
  7.     }

a) A
b) a
c) Non-zero number
d) Zero
Answer: b
Clarification: None.

6. Which types of input are accepted in toupper(c)?
a) char
b) char *
c) float
d) Both char and char *
Answer: a
Clarification: None.

7. What is the difference in the ASCII value of capital and non-capital of the same letter is?
a) 1
b) 16
c) 32
d) Depends with compiler
Answer: c
Clarification: None.

250+ TOP MCQs on Float Datatype and Answers

tricky C Objective Questions on “Float Datatype”. One shall practice these tricky questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Float Datatype” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

    #include 
    printf("%.0f", 2.89);

a) 2.890000
b) 2.89
c) 2
d) 3
Answer: d
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         float a = 2.455555555555;
  5.         printf("%f", a);
  6.     }

a) 2.455555
b) 2.455556
c) 2.456
d) 2.46
Answer: a
Clarification: None.

3. Which of the following % operation is invalid?
a) 2 % 4;
b) 2 % 4l;
c) 2 % 4f;
d) Both 2 % 4l; and 2 % 4f;
Answer: c
Clarification: None.

4. Which data type is suitable for storing a number like?

10.0000000001

a) int
b) float
c) double
d) both float and double
Answer: c
Clarification: None.

5. Modulus for float could be achieved by?
a) a % b
b) modulus(a, b);
c) fmod(a, b);
d) mod(a, b);
Answer: c
Clarification: None.

6. Predict the data type of the following mathematical operation?

2 * 9 + 3 / 2 . 0

a) int
b) long
c) float
d) double
Answer: d
Clarification: None.

7. %lf is used to display?
a) float
b) long float
c) double
d) all of the mentioned
Answer: c
Clarification: None.

250+ TOP MCQs on General Utilities and Answers

C MCQs on “General Utilities – 5”.

1. The number of bytes contained in the multibyte character pointed to by a character is ___________
a) getenv()
b) bsearch()
c) mblen()
d) qsort()
Answer: c
Clarification: int mblen(const char *s, size-t n);
If s is not a null pointer, the mblen() function is used to determine the number of bytes contained in the multibyte character pointed to by s.

2. The pointer used in the mblen() function points to the _________
a) first byte of multibyte character
b) last byte of multibyte character
c) middle byte of multibyte character
d) no pointer is used in mblen function
Answer: a
Clarification: The prototype of the functon mblen() is int mblen(const char *s,size_t n); The pointer ‘s’ points to the first byte of the multibyte character.

3. What is the name of the function that is used to convert multibyte character to wide character?
a) mblen()
b) mbtowc()
c) mbstowcs()
d) wcstombs()
Answer: b
Clarification: mbtowc() function is used to convert the multibyte character to wide character.

4. Which function converts the wide-character string to a multibyte string?
a) wcstombs()
b) mbstowcs()
c) mbtowc()
d) mblen()
Answer: a
Clarification: The C library function size_t wcstombs(char *ptr, const wchar_t *ws, size_t n) is used to convert the wide-character string was to a multibyte string starting at ptr. At most n bytes are written to ptr.

5. The C library function _____________function converts the wide character to its multibyte representation.
a) mblen()
b) mbtowc()
c) wcstombs()
d) wctomb()
Answer: d
Clarification: wctomb() is a C Library function which converts the wide character into its multibyte representation. It is stored at the beginning of the character array pointed to by the respective pointer.

6. The mbstowcs() function is used to return the number of array elements modified, not including a terminating zero code, if any.
a) true
b) false
Answer: a
Clarification: mbstowcs() function returns the number of array elements that are modified. It does not return a terminating zero code if any. The mbstowcs() function is used to convert a sequence of multibyte characters that begins in the initial shift state from the array pointed to by, into a sequence of corresponding codes.

7. What will the given C code do?

#include  
_Mbsave_Mbxlen={0};
int (mblen)(const char *s ,size_t n)
{
return(_Mbtowc(NULL s,n,&_Mbxlen));
}

a) determine length of next multibyte code
b) determine next multibyte code
c) translate multibyte string to wide char string
d) translate wide character to multibyte string
Answer: a
Clarification: mblen() function is used to return the length of a multi-byte character pointed to, by the argument s. The data objects _Mbxlen and _Mbxtowc both have names with external linkage.

8. What is the purpose of the given C code?

#include  
_Mbsave _Mbxtowc = {0};  
int (mbtowc) (wchar_t *pwc, const char *a, size_t n) 
{
return (-Mbtowc (pwc, s, n, &-Mbxtowc) ) ;
}

a) determine length of next multibyte code
b) translates multibyte character to wide character
c) translate multibyte string to wide char string
d) translate wide character to multibyte string
Answer: b
Clarification: int mbtowc(whcar_t *pwc, const char *a, size_t n)
The given function is used to convert a multibyte sequence to a wide character.

9. What is “a” in the given C code?

size_t wcstombs(char *s, const wchar_t *a, size_t n)

a) “a” is wide character string to be converted
b) “a” is pointer to an array of char elements
c) “a” is pointer to the first byte of a multi-byte character
d) “a” C multibyte character string to be interpreted
Answer: a
Clarification: The wcstombs() function is used to convert a sequence of codes that correspond to multibyte characters from the array pointed to by ‘a’ into a sequence of multibyte characters beginning in the initial shift state and stores these multibyte characters into the array pointed to by s.
size_t wcstombs(char *s, const wchar_t *a, size_t n)

10. mblen() function returns 0,if a null wide character was recognized. It returns -1 if an invalid multi-byte sequence was encountered.
a) true
b) false
Answer: a
Clarification: int mblen(const char *a, size-t n);
If in the given code “a” points to a NULL character then the function returns 0 or -1 is returned if they do not form a valid multibyte character.

250+ TOP MCQs on DMA Functions, Memory Leak, Dangling Pointers and Answers

C Multiple Choice Questions & Answers (MCQs) on “DMA Functions, Memory Leak, Dangling Pointers – 1”.

1. What will be the output of the following C code if the input entered as first and second number is 5 and 6 respectively?

#include
#include
main()
{
    int *p;
    p=(int*)calloc(3*sizeof(int));
    printf("Enter first numbern");
    scanf("%d",p);
    printf("Enter second numbern");
    scanf("%d",p+2);
    printf("%d%d",*p,*(p+2));
    free(p);
}

a) 56
b) Address of the locations where the two numbers are stored
c) 57
d) Error
Answer: d
Clarification: The above code results in an error. This is because the syntax of the function calloc() is incorrect. In order to rectify this error, we must write: calloc(3,sizeof(int));

2. In the function malloc(), each byte of allocated space is initialized to zero.
a) True
b) False
Answer: b
Clarification: In the function malloc(), allocated space is initialized to junk values. In calloc(), each byte of allocated space is initialized to zero.

3. Which of the following functions allocates multiple blocks of memory, each block of the same size?
a) malloc()
b) realloc()
c) calloc()
d) free()
Answer: c
Clarification: malloc() allocates a single block of memory whereas calloc() allocates multiple blocks of memory, each block with the same size.

4. A condition where in memory is reserved dynamically but not accessible to any of the programs is called _____________
a) Memory leak
b) Dangling pointer
c) Frozen memory
d) Pointer leak
Answer: a
Clarification: If we allocate memory dynamically in a function (malloc, calloc, realloc), the allocated memory will not be de-allocated automatically when the control comes out of the function. This allocated memory cannot be accessed and hence cannot be used. This unused inaccessible memory results in a memory leak.

5. What will happens if the statement free(a) is removed in the following C code?

#include
#include
main()
{
    int *a;
    a=(int*)malloc(sizeof(int));
    *a=100;
    printf("*a%d",*a);
    free(a);
    a=(int*)malloc(sizeof(int));
    *a=200;
    printf("a%p",a);
    *a=200;
    printf("a%d",*a);
}

a) Error
b) Memory leak
c) Dangling pointer arises
d) 200 is printed as output
Answer: b
Clarification: The pointer ‘a’ points to the recent value 200, making the memory allocated earlier inaccessible. Hence, the memory where the value 100 is inaccessible and cannot be freed. Therefore, memory leak occurs.

6. The incorrect statement with respect to dangling pointers is ___________
a) Pointer pointing to non-existent memory location is called dangling pointer
b) When a dynamically allocated pointer references the original memory after it has been freed, a dangling pointer arises
c) If memory leak occurs, it is mandatory that a dangling pointer arises
d) Dangling pointer may result in segmentation faults and potential security risks
Answer: c
Clarification: Memory leak and dangling pointers are not inter dependent. Hence, when memory leak occurs, it is not mandatory that a dangling pointer arises

7. What will be the output of the following C code?

#include
#include
void main()
{
    char *p = calloc(100, 1);
    p = "welcome";
    printf("%sn", p);
}

a) error
b) welcome
c) memory location stored by the pointer
d) junk value
Answer: b
Clarification: There is no error in the above code. The format specifier being %s, address is not returned. Hence, welcome is the output.

8. In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory ___________
a) is initialized to junk values
b) is initialized to zero
c) results in an error
d) is not initialized
Answer: d
Clarification: The function realloc() changes the size of a particular memory block. If the new size is larger than the old size, the added memory is not initialized.

9. The free() function frees the memory state pointed to by a pointer and returns ___________
a) the same pointer
b) the memory address
c) no value
d) an integer value
Answer: c
Clarification: The free() function frees the memory state pointed by a pointer and returns no value.

10. The following C code is an example of __________

#include
#include
#include
main()
{
    char *p,*q;
    p=(char*)malloc(3*sizeof(char));
    q=p;
    strcpy(p,"hello");
    printf("p=%s",p);
    printf("q=%s",q);
    free(q);
    q=NULL;
    gets(p);
    gets(q);
    printf("%s",p);
    printf(%s”,q);
}

a) Memory leak
b) Dangling pointer
c) Static memory allocation
d) Linked list
Answer: b
Clarification: In the above code, the pointer p, points to a memory location which has been freed. Hece the above code is an example of dangling pointer.

250+ TOP MCQs on Declarations and Answers

C Objective Questions on “Declarations”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with the detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Declarations” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     void foo(const int *);
  3.     int main()
  4.     {
  5.         const int i = 10;
  6.         printf("%d ", i);
  7.         foo(&i);
  8.         printf("%d", i);
  9.  
  10.     }
  11.     void foo(const int *i)
  12.     {
  13.         *i = 20;
  14.     }

a) Compile time error
b) 10 20
c) Undefined value
d) 10
Answer: a
Clarification: Cannot change a const type value.
Output:
$ cc pgm1.c
pgm1.c: In function ‘foo’:
pgm1.c:13: error: assignment of read-only location ‘*i’

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         const int i = 10;
  5.         int *ptr = &i;
  6.         *ptr = 20;
  7.         printf("%dn", i);
  8.         return 0;
  9.     }

a) Compile time error
b) Compile time warning and printf displays 20
c) Undefined behaviour
d) 10
Answer: b
Clarification: Changing const variable through non-constant pointers invokes compiler warning.
Output:
$ cc pgm2.c
pgm2.c: In function ‘main’:
pgm2.c:5: warning: initialization discards qualifiers from pointer target type
$ a.out
20

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         j = 10;
  5.         printf("%dn", j++);
  6.         return 0;
  7.     }

a) 10
b) 11
c) Compile time error
d) 0
Answer: c
Clarification: Variable j is not defined.
Output:
$ cc pgm3.c
pgm3.c: In function ‘main’:
pgm3.c:4: error: ‘j’ undeclared (first use in this function)
pgm3.c:4: error: (Each undeclared identifier is reported only once
pgm3.c:4: error: for each function it appears in.)

4. Will the following C code compile without any error?

  1.     #include 
  2.     int main()
  3.     {
  4.         for (int k = 0; k < 10; k++);
  5.             return 0;
  6.     }

a) Yes
b) No
c) Depends on the C standard implemented by compilers
d) Error
Answer: c
Clarification: Compilers implementing C90 do not allow this, but compilers implementing C99 allow it.
Output:
$ cc pgm4.c
pgm4.c: In function ‘main’:
pgm4.c:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code

5. Will the following C code compile without any error?

  1.     #include 
  2.     int main()
  3.     {
  4.         int k;
  5.         {
  6.             int k;
  7.             for (k = 0; k < 10; k++);
  8.         }
  9.     }

a) Yes
b) No
c) Depends on the compiler
d) Depends on the C standard implemented by compilers
Answer: a
Clarification: There can be blocks inside the block. But within a block, variables have only block scope.
Output:
$ cc pgm5.c

6. Which of the following declaration is not supported by C?
a) String str;
b) char *str;
c) float str = 3e2;
d) Both String str; & float str = 3e2;
Answer: a
Clarification: It is legal in Java, but not in C.

7. Which of the following format identifier can never be used for the variable var?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *var = "Advanced Training in C by .com";
  5.     }

a) %f
b) %d
c) %c
d) %s
Answer: a
Clarification: %c can be used to print the indexed position.
%d can still be used to display its ASCII value.
%s is recommended.
%f cannot be used for the variable var.

250+ TOP MCQs on Precedence and Order of Evaluation and Answers

online C test on “Precedence and Order of Evaluation”. One shall practice these test questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our online C test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of online C test questions on “Precedence and Order of Evaluation” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5 * 3 + 2 - 4;
  5.         printf("%d", a);
  6.     }

a) 13
b) 14
c) 12
d) 1 6
Answer: a
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 2 + 4 + 3 * 5 / 3 - 5;
  5.         printf("%d", a);
  6.     }

a) 7
b) 6
c) 10
d) 9
Answer: b
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5 * 3 % 6 - 8 + 3;
  5.         printf("%d", a);
  6.     }

a) 10
b) 2
c) -2
d) -3
Answer: c
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int b = 6;
  5.         int c = 7;
  6.         int a = ++b + c--;
  7.         printf("%d", a);
  8.     }

a) Run time error
b) 15
c) 13
d) 14
Answer: d
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     void main(
  3.     {
  4.         double b = 8;
  5.         b++;
  6.         printf("%lf", b);
  7.     }

a) 9.000000
b) 9
c) 9.0
d) Run time error
Answer: a
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 3 % 0 * 1 - 4 / 2;
  5.         printf("%lf", b);
  6.     }

a) -2
b) Floating point Exception
c) 1
d) 0
Answer: b
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 5 % 3 & 4 + 5 * 6;
  5.         printf("%lf", b);
  6.     }

a) 2
b) 30
c) 2.000000
d) Run time error
Answer: c
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 3 && 5 & 4 % 3;
  5.         printf("%lf", b);
  6.     }

a) 3.000000
b) 4.000000
c) 5.000000
d) 1.000000
Answer: d
Clarification: None.

9. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 5 & 3 && 4 || 5 | 6;
  5.         printf("%lf", b);
  6.     }

a) 1.000000
b) 0.000000
c) 7.000000
d) 2.000000
Answer: a
Clarification: None.

10. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         double b = k++ + ++k + k--;
  6.         printf("%d", k);
  7.     }

a) 6
b) 1
c) 5
d) undefined
Answer: d
Clarification: None.