Advertisements

Search results for char

Example:[1]

            What is the output of the following program if array starts with address 8432 and char is of 1byte?
#include <stdio.h>
int main()
{
	char array[5] = {'A','B','C','D','E'};
	printf("%u,%u\n",&array[1],&array[3]);
}

          
Option A:

            8433,8435
            
Option B:

            8432,8434
            
Option C:

            8434,8436
            
Option D:

            8431,8433
            
Correct Answer: option A
Example:[2]

            Which of the following array declaration is wrong?
char array[5] = {'A','B','C','D','E'};
int ar[5] = {1,2,3,4,5,6};
char a[] = {'a','b','c','d','e','f'};

          
Option A:

            char array[5] = {'A','B','C','D','E'};
            
Option B:

            int ar[5] = {1,2,3,4,5,6};
            
Option C:

            char a[] = {'a','b','c','d','e','f'};
            
Option D:

            All array declarations are correct.
            
Correct Answer: option B
Example:[3]

            Which of the following declaration is a string?
char array[5] = {'A','B','C','D','E'};
int ar[5] = {1,2,3,4,5};
char a[] = {'a','b','c','d','e','f'};
char arr[] = {'a','b','c','d','e','f','\0'};

          
Option A:

            char array[5] = {'A','B','C','D','E'};
            
Option B:

            int ar[5] = {1,2,3,4,5};
            
Option C:

            char a[] = {'a','b','c','d','e','f'};
            
Option D:

            char arr[] = {'a','b','c','d','e','f','\0'};
            
Correct Answer: option D
Example:[4]

            What will be the output of the following program if first character w of two dimensional array arr starts at memory location 2000?
#include<stdio.h>
int main(){
char arr[5][10] = {
"white",
"red",
"green",
"yellow",
"blue"
};
printf("%s and %u",arr[2],&arr[2][2]);
}
          
Option A:

            green and 2022
            
Option B:

            green and 2012
            
Option C:

            blue and 2002
            
Option D:

            yellow and 2052
            
Correct Answer: option A
Example:[5]

            What will be the output of the following program?
#include <stdio.h>
int main(){
char arr[5][10] = {
"white",
"red",
"green",
"yellow",
"blue"
};
printf("%d",sizeof(arr));
}
          
Option A:

            10
            
Option B:

            5
            
Option C:

            50
            
Option D:

            38
            
Correct Answer: option C
Example:[6]

            What is the following declaration all about?
	char Arr[2][32] = 
	{
	    {"Sibal"},
	    {"Srikant"}
   	};
          
Option A:

            Arr is an array of strings and it will occupy a fixed size of 64 bytes in memory.
            
Option B:

            Arr is an array of strings and it will occupy a fixed size of 14 bytes in memory.
            
Option C:

            Arr is an array of pointers to strings and it will occupy a fixed size of 64 bytes in memory.
            
Option D:

            Arr is an array of pointers to strings and it will occupy a fixed size of 14 bytes in memory.
            
Correct Answer: option A
Example:[7]

            What is the output of the following program?
#include <stdio.h> 
#include <string.h> 
char func(char *);
void main ()  
{  
    char res;
    res = func("Hello");
    printf("%c\n", res);
}  
char func(char *s)
{
  return s[strlen(s)-1];
}
          
Option A:

            l
            
Option B:

            o
            
Option C:

            H
            
Option D:

            '\0'
            
Correct Answer: option B
Example:[8]

            What is the output of the following program?
#include <stdio.h> 
int func(char *);
void main ()  
{  
    int res;
    res = func("Hello");
    printf("%d\n", res);
}  
int func(char *s)
{
  int len = 0;
  for(int i = 0;s[i] != '\0';i++)
  {
    len++;
  }
  return len;
}
          
Option A:

            4
            
Option B:

            6
            
Option C:

            5
            
Option D:

            3
            
Correct Answer: option C
Example:[9]

            What is the output of the following program?
#include <stdio.h> 
#include <string.h> 
void main ()  
{  
    char s[10];
    strcpy(s,"friend");
    printf("%d,%d\n", strlen(s),sizeof(s));
}
          
Option A:

            6,6
            
Option B:

            5,9
            
Option C:

            7,10
            
Option D:

            6,10
            
Correct Answer: option D
Example:[10]

            What is the error on the following program, currently it returns garbage value as output?
#include <stdio.h>
#include <string.h>
char *fun();
void main()
{
    char *s;
    char *fun();
    s = fun();
    printf("%s\n", s);
}
char *fun()
{
    char buffer[30];
    strcpy(buffer, "RAM");
    return (buffer);
}
          
Option A:

            Declare buffer as a global variable.
            
Option B:

            Declare char *s outside main function.
            
Option C:

            Include header file stdlib.h.
            
Option D:

            Allocate memory using malloc inside main()
            
Correct Answer: option A
Example:[11]

            Which of the following is NOT a string declaration?
          
Option A:

            char *str1 = "Hello";
            
Option B:

            char str2[] = "Hello";
            
Option C:

            char str3[] = {'H','e','l','l','o'};
            
Option D:

            char str4[] = {'H','e','l','l','o','\0'};
            
Correct Answer: option C
Example:[12]

            What is the output of the following program?
#include <stdio.h> 
void main ()  
{  
    char a[] = "Hello";
    printf("%s\n", 'a');
}  
          
Option A:

            a
            
Option B:

            H
            
Option C:

            Hello
            
Option D:

            Segmentation fault during execution
            
Correct Answer: option D
Example:[13]

            What will strcmp() library function do?
          
Option A:

            compares the first n characters of the object
            
Option B:

            compares two strings and returns an integer
            
Option C:

            compares two integers and returns a string
            
Option D:

            copies one string to other
            
Correct Answer: option B
Example:[14]

            What is the output of the following program?
#include <stdio.h>
#include <string.h>
int main()
{
    char str1[] = "abc", str2[] = "Abc", str3[] = "abc";
    int result1,result2;
    result1 = strcmp(str1, str2);
    result2 = strcmp(str1, str3);
    printf("%d,%d\n", result1,result2);
    return 0;
}
          
Option A:

            32,0
            
Option B:

            0,32
            
Option C:

            32,32
            
Option D:

            0,0
            
Correct Answer: option A
Example:[15]

            What will strcat() library function do?
          
Option A:

            compares the first n characters of the object
            
Option B:

            compares two strings and returns an integer
            
Option C:

            concatenates two strings and returns the concatenated string
            
Option D:

            copies one string to other
            
Correct Answer: option C
Example:[16]

            #include <stdio.h>
#include <string.h>
int main()
{
    char str1[10] = "Mbed", str2[] = "Tech";
    strcat(str1,str2);
    printf("%s,%s\n", str1,str2);
    return 0;
}
          
Option A:

            MbedTech,Tech
            
Option B:

            Tech,Tech
            
Option C:

            MbedTech,MbedTech
            
Option D:

            Compilation error
            
Correct Answer: option A
Example:[17]

            What is the output of the following program?
#include <stdio.h>
char *func(char *);
void main()
{
    char str1[] = "MbedTechnologies";
    char *res;
    res = func(str1);
	printf("%s", res);
}
char *func(char *s)
{
	s[4] = '\0';
	return s;
}
          
Option A:

            MbedTechnologies
            
Option B:

            Technologies
            
Option C:

            Mbed
            
Option D:

            Compilation error
            
Correct Answer: option C
Example:[18]

            What is the output of the following program?
#include <stdio.h>
#include <string.h>
void main()
{
    char str1[] = "Mbed";
    char *res;
    strcpy(res,str1);
    printf("%s", res);
}
          
Option A:

            Machine dependent
            
Option B:

            Compilation error
            
Option C:

            Mbed
            
Option D:

            Compilation ok, Segmentation fault during execution
            
Correct Answer: option D
Example:[19]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
int main() {
  char strs[] = "Bangalore-2134";
  char *strd = strs + 5;
  strcat(strd, strs);
  printf("strd is %s\n",strd);
  return 0;
}
          
Option A:

            Segmentation fault
            
Option B:

            Bangalore-2134Banga
            
Option C:

            BangaBangalore-2134
            
Option D:

            Bangalore-2134
            
Correct Answer: option A
Example:[20]

            What is the output of the following program?
#include <stdio.h>
void main ()
{
	char str[] = "Mbed Technologies";
	printf("%c,%s\n", str[1], str);
}
          
Option A:

            M,MbedTechnologies
            
Option B:

            M,Mbed
            
Option C:

            b,Mbed Technologies
            
Option D:

            M,Mbed Technologies
            
Correct Answer: option C
Example:[21]

            What is the output of the following program?
#include <stdio.h>
int main ()
{
	char s1[] = "Mbed";
	char s2[] = {'M','b','e','d',0};
	printf("%s,%s\n", s1,s2);
	return 0;
}
          
Option A:

            Mbed,Mbed
            
Option B:

            Mbed,''Mbed''
            
Option C:

            Mbed
            
Option D:

            Mbed,'Mbed'
            
Correct Answer: option A
Example:[22]

            What is the output of the following program?
#include <stdio.h>
int main ()
{
	char s[] = "Mbed";
	printf("%s,%s,%s,%c\n", s,&s[2],&s,s[2]);
	return 0;
}
          
Option A:

            Mbed,ed,Mbed,b
            
Option B:

            Mbed,ed,1e4d55e0,e
            
Option C:

            Mbed,Mbed,Mbed,e
            
Option D:

            Mbed,ed,Mbed,e
            
Correct Answer: option D
Example:[23]

            What is the output of the following program?
#include <stdio.h>
int main ()
{
        char s[] = "Mbed";
        int i = 0;
        while(s[i] != 0)
        {
                printf("%c %c %c\n", s[i], *(s + i), *(i + s));
                i++;
        }
        return 0;
}
          
Option A:

            b  b  b
e  e  e
d  d  d
M  M  M
            
Option B:

            M  M  M
b  b  b
e  e  e
d  d  d
            
Option C:

            M  M  M
b  b  b
d  d  d
e  e  e
            
Option D:

            M  M  M
e  e  e
b  b  b
d  d  d
            
Correct Answer: option B
Example:[24]

            What is the output of the following program?
#include "stdio.h"
int main(void)
{
  char str[2][15] =
  {
    "Mbed",
    "Technologies"
  };
  printf("%d,%s,%c\n",sizeof(str),str[1],str[0][0]);
}
          
Option A:

            30,M,Technologies
            
Option B:

            30,Technologies,M
            
Option C:

            30,T,M
            
Option D:

            30,e,M
            
Correct Answer: option B
Example:[25]

            What is the output of the following program?
#include "stdio.h"
int main(void)
{
  char *str[] =
  {
    "Mbed",
    "Technologies"
  };
  printf("%d,%s,%c\n",sizeof(str),str[1],str[0][0]);
}
          
Option A:

            18,Technologies,M
            
Option B:

            8,Technologies,M
            
Option C:

            8,T,M
            
Option D:

            30,e,M
            
Correct Answer: option B
Example:[26]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
int main() {
  char strs[] = "Bangalore-2134";
  char strd[10] = "\0";
  strncpy(strd, strs, 9);
  printf("strd is %s\n",strd);
  return 0;
}
          
Option A:

            strd is 2134
            
Option B:

            strd is Bangalore
            
Option C:

            strd is 2134Bangalore
            
Option D:

            strd is Bangalore2134
            
Correct Answer: option B
Example:[27]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
int main() {
  char strs[] = "Bangalore-2134";
  char strd[10];
  strd[0] = '\0';
  strncat(strd, strs, 9);
  printf("strd is %s\n",strd);
  return 0;
}
          
Option A:

            strd is 2134
            
Option B:

            strd is Bangalore
            
Option C:

            strd is 2134Bangalore
            
Option D:

            strd is Bangalore2134
            
Correct Answer: option B
Example:[28]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
int main() {
  char strs[] = "Bangalore";
  char strd[] = "2134";
  strcat(strd, strs);
  printf("strd is %s\n",strd);
  return 0;
}
          
Option A:

            strd is 2134
            
Option B:

            strd is Bangalore
            
Option C:

            strd is 2134Bangalore
            
Option D:

            strd is Bangalore2134
            
Correct Answer: option C
Example:[29]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
int main() {
  char str1[] = "Mbed Technologies";
  char str2[] = "Mbed Articles";  
  int i1 = strcmp(str1, str1);
  int i2 = strcmp(str1, str2);
  int i3 = strcmp(str2, str1);
  printf("%d, %d, %d\n", i1, i2, i3);  
  return 0;
}
          
Option A:

            19, 0, -19
            
Option B:

            19, -19, 0
            
Option C:

            0, 19, 0
            
Option D:

            0, 19, -19
            
Correct Answer: option D
Example:[30]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
int main() {
  char str1[] = "Mbed Technologies";
  char str2[] = "Mbed Articles";
  int i1 = strncmp(str1, str2, 4);
  int i2 = strncmp(str1, str2, 9);
  int i3 = strncmp(str2, str1, 9);
  printf("%d, %d, %d\n", i1, i2, i3);  
  return 0;
}
          
Option A:

            19, 0, -19
            
Option B:

            19, -19, 0
            
Option C:

            0, 19, 0
            
Option D:

            0, 19, -19
            
Correct Answer: option D
Example:[31]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
void main() {
	char *ptr;
	char str[] = "Mbed Technologies";
	char ch = 'e';
	ptr = strrchr(str, ch);
	printf( "%c %s %s\n",ch, str, ptr);
}
          
Option A:

            e Mbed Technologies es
            
Option B:

            e Mbed Technologies echnologies
            
Option C:

            e Mbed Technologies e
            
Option D:

            e Mbed Technologies ed Technologies
            
Correct Answer: option A
Example:[32]

            What is the output of the following program?
#include "stdio.h"
#include "string.h"
void main() {
	char *ptr;
	char str[] = "Mbed Technologies";
	char ch = 'e';
	ptr = strchr(str, ch);
	printf( "%c %s %s\n",ch, str, ptr);
}
          
Option A:

            e Mbed Technologies es
            
Option B:

            e Mbed Technologies echnologies
            
Option C:

            e Mbed Technologies e
            
Option D:

            e Mbed Technologies ed Technologies
            
Correct Answer: option D
Example:[33]

            What is a pointer in C?
          
Option A:

            Pointers in C language is a variable that stores/points the address of another variable.
            
Option B:

            A Pointer in C is used to allocate memory dynamically i.e. at run time.
            
Option C:

            The pointer variable might be belonging to any of the data type such as int, float, char, double, short etc.
            
Option D:

            All of the above.
            
Correct Answer: option D
Example:[34]

            What would be the output of following program?
#include <stdio.h>
int main()
{
    char str[20] = "Master";
    char *p = str;
    *p = 'F';
    p++;p++;
    *p = 'S';
    p++;p++;
    *p = 'E';
    printf("%s\n", str);
    return 0;
}
          
Option A:

            Master
            
Option B:

            MaStEr
            
Option C:

            FaStEr
            
Option D:

            FastEr
            
Correct Answer: option C
Example:[35]

            What is the following declaration all about?
char *Arr[] = 
   {
   		"Jena",
   		"Kumar"	
   };
          
Option A:

            Arr is an array of strings
            
Option B:

            Arr is a string.
            
Option C:

            Arr is a pointer to string.
            
Option D:

            Arr is an array of pointers to strings.
            
Correct Answer: option D
Example:[36]

            What would be the output of following program?
#include <stdio.h>
void main()
{
  char *Arr[] = 
  {
    "Jena",
    "Kumar" 
  };
  printf("%c,%s\n", Arr[1][3],Arr[1]);
}
          
Option A:

            a,Jena
            
Option B:

            J,Jena
            
Option C:

            a,Kumar
            
Option D:

            u,Kumar
            
Correct Answer: option C
Example:[37]

            What is the output of the following c program?
#include <stdio.h>
void main()
{
    unsigned int i = 0x00000001;
    char *c = (char *)&i;
    printf("%d\n", *c);
}
          
Option A:

            1
            
Option B:

            0
            
Option C:

            1 if machine is little endian, 0 if machine is big endian
            
Option D:

            Compile error
            
Correct Answer: option C
Example:[38]

            What is the output of the following program?
#include <stdio.h>
#include <string.h>
struct test
{
  char s[10];
};
void myfunc(struct test *d)
{
  strcpy(d->s,"World");
}
void main()
{
  struct test t;
  myfunc(&t);
  printf("%s", t.s);
}
          
Option A:

            No output
            
Option B:

            World
            
Option C:

            Compile error
            
Option D:

            Garbage output
            
Correct Answer: option B
Example:[39]

            What is the output of the following program?
#include <stdio.h>
#include <string.h>
void myfunc(struct test *d)
{
  strcpy(d->s,"World");
}
void main()
{
  struct test
  {
    char s[10];
  };
  struct test t;
  myfunc(&t);
  printf("%s", t.s);
}
          
Option A:

            No output
            
Option B:

            World
            
Option C:

            Compile error
            
Option D:

            Garbage output
            
Correct Answer: option C
Example:[40]

            What will be error the following program will face during execution?
#include <stdio.h> 
#include <string.h> 
void main ()  
{  
    char a[2] = "";
    strcpy(a,"Hello World");
    printf("%s\n", a);
}

          
Option A:

            Stack overflow
            
Option B:

            Heap overflow
            
Option C:

            Frozen memory
            
Option D:

            Memory leak
            
Correct Answer: option A
Example:[41]

            What will be error the following program will face during execution?
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#define BUFSIZE 2
void main() 
{
    char *buf;
    buf = (char *)malloc(sizeof(char)*BUFSIZE);
    strcpy(buf, "Hello world\n");
}
          
Option A:

            Stack overflow
            
Option B:

            Heap overflow
            
Option C:

            Frozen memory
            
Option D:

            Memory leak
            
Correct Answer: option B
Example:[42]

            What will be error the following program will face during execution?
#include <stdio.h>
int main()
{
    char i[5] = "";
    scanf("%s", i);
    printf("%s",i);
    return 0;
}
          
Option A:

            Buffer overflow
            
Option B:

            Heap overflow
            
Option C:

            Frozen memory
            
Option D:

            Memory leak
            
Correct Answer: option A
Example:[43]

            What will be the output of the following program?
#include <stdio.h>
union mass
{
   	unsigned int a;
   	char b;
};
void main()
{
    union mass test;
    test.a = 0x00000001;
    printf("%d\n", test.b);
}
          
Option A:

            1
            
Option B:

            0
            
Option C:

            1 if machine is little endian, 0 if machine is big endian
            
Option D:

            Compile error
            
Correct Answer: option C
Example:[44]

            What will be the output of the following program if int takes 4 bytes and char takes 1 byte?
#include <stdio.h>
union mass
{
   	unsigned int a;
   	char b;
};
void main()
{
	union mass u;
    printf("%d\n", sizeof(u));
}
          
Option A:

            1
            
Option B:

            5
            
Option C:

            4
            
Option D:

            6
            
Correct Answer: option C
Example:[45]

            What will be the output of the following program if int takes 4 bytes and char takes 1 byte?
#include <stdio.h>
struct student
{
   	int a;
   	char b;
};
void main()
{
	struct student s;
    printf("%d\n", sizeof(s));
}
          
Option A:

            1
            
Option B:

            5
            
Option C:

            4
            
Option D:

            6
            
Correct Answer: option B
Example:[46]

            What will be the output of the following program?
#include <stdio.h>
unsigned char fun(unsigned char );
void main()  
{  
    unsigned char y;
    y = fun(0x12);
    printf("%x\n", y);
}
unsigned char fun(unsigned char a)
{
   return ((a << 4) | (a >> 4));
}
          
Option A:

            21
            
Option B:

            12
            
Option C:

            18
            
Option D:

            33
            
Correct Answer: option A
Example:[47]

            In linked list each node contains minimum of two fields. The first field is to store the data and the second field is which of the following?
          
Option A:

            Pointer to character
            
Option B:

            Pointer to integer
            
Option C:

            Pointer to node structure
            
Option D:

            Pointer to float
            
Correct Answer: option C

 Search Links


 Popular C search MCQs


 Popular C search examples