August 26, 2019

Computer Programming - MCQS

Note: We have tried to upload as much as we can, all the question and answers might be shuffled - Please find the answer below each question, some answers might be wrong please review on the last date(some answers might be changed) if you find any wrong answer please comment down below.


Question 1
Which among the following is not an usage of structure?
Select one:
A. Changing the size of the cursor
B. Receiving a key from the keyboard
C. Placing the cursor at an appropriate position on screen
D. Drawing any graphics shape on the screen
E. None of the options
Correct Answer: E

Question 2
#include <stdio.h>
struct sample
{
                int a=0;
                char b='A';
                float c=10.5;
};
int main()
{
                struct sample s;
                printf("%d,%c,%f",s.a,s.b,s.c);
                return 0;
}
Select one:
A. No Error, No Output
B. 0, A, 10.5
C. Error
D. 0, A, 10.500000
Correct Answer: C

Question 3
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20] = "Hello", str2[20] = " Program";
    printf("%s\n", strcpy(str2, strcat(str1, str2)));
    return 0;
}
Select one:
A. ProgramHello
B. Program
C. Hello Program
D. Hello
Correct Answer: C

Question 4
What will be the output of the program?
#include<stdio.h>
int main()
{
    static char s[25] = "C-Programming-skills";
    int i=0;
    char ch;
    ch = s[++i];
    printf("%c", ch);
    ch = s[i++];
    printf("%c", ch);
    ch = i++[s];
    printf("%c", ch);
    ch = ++i[s];
    printf("%c", ch);
    return 0;
}
Select one:
A. --Ps
B. C--s
C. C-Pr
D. -Pro
Correct Answer: A

Question 5
Which among the following is true about srtcmpi()?
Select one:
A. Compares two strings
B. Compares two strings with regard to case
C. Compares first n characters of two strings
D. Compares two strings without regard to case
Correct Answer: D

Question 6
Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);
Select one:
A. char p = *malloc(100);
B. char *p = (char *)(malloc*)(100);
C. char *p = (char) malloc(100);
D. char *p = (char*)malloc(100)
Correct Answer: D

Question 7
# include <stdio.h>
void print(int arr[])
{
   int n = sizeof(arr)/sizeof(arr[0]);
   int i;
   for (i = 0; i < n; i++)
   printf("%d ", arr[i]);
}
int main()
{
   int arr[] = {4,5,7,1,2,6,7,8};
   print(arr);
   return 0;
}
Select one:
A. 4,5,7,1,2,6,7,8
B. Compile error
C. Run time error
D. 4 5
Correct Answer: D

Question 8
#include<stdio.h>
int i;
int fun();
int main()
{
    while(i)
    {
        fun();
        main();
    }
    printf("Hello");
    return 0;
}
int fun()
{
    printf("Hi");
}
Select one:
A. Infinite loop
B. Hello
C. No output
D. Hi Hello
Correct Answer: B

Question 9
#include&lt;stdio.h&gt;
void fun(int*, int*);
int main()
{
int i=5, j=2;
fun(&amp;i, &amp;j);
printf(&quot;%d, %d&quot;, i, j);
return 0;
}
void fun(int *i, int *j)
{
*i = *i**i;
*j = *j**j;
}
Select one:
A. 2, 5
B. 25, 4
C. 5, 2
D. 10, 4
Correct Answer: B

Question 10
Find the odd man out in the following:
Select one:
A. N[i]
B. *N+i
C. *(i+N)
D. *(N+i)
Correct Answer: B

Question 11
What will be the output of the program?
#include<stdio.h>
    struct course
    {
        int courseno;
        char coursename[25];
    };
int main()
{
    struct course c[] = { {102, "Ruby"},
                          {103, "Scala"},
                          {104, "Python"}     };
    printf("%d ", c[1].courseno);
    return 0;
}
Select one:
A. 104
B. 102
C. 103
D. Error
Correct Answer: C

Question 12
int main()
{
    int i;
    int arr[5] = {1};
    for (i = 0; i < 5; i++)
    printf("%d ", arr[i]);
    return 0;
}
Select one:
A. 11111
B. error
C. 10000
D. 00000
Correct Answer: C

Question 13
How will you free the allocated memory ?
Select one:
A. delete(var-name);
B. free(var-name);
C. remove(var-name);
D. dalloc(var-name);
Correct Answer: B

Question 14
___________is a macro which returns a 0 if end of file is not reached.
Select one:
A. Feof()
B. Ferror()
C. Fscanf()
D. Fprintf()
Correct Answer: A

Question 15
Can we receive input from keyboard for the array of pointers to strings?
Select one:
A. Yes
B. Rarely
C. No
D. May be
Correct Answer: C

Question 16
Accessing array elements by pointers is _____________ faster than accessing them
by subscripts.
Select one:
A. Not
B. Always
C. Sometimes
D. Probably
Correct Answer: B

Question 17
Which among the following is the drawback of putch, putchar, fputchar()?
Select one:
A. Outputs only one character at a time
B. None of the above
C. Comes out of the screen
D. Outputs more than one character at a time
Correct Answer: A

Question 18
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    char sentence[80];
    int i;
    printf("Enter a line of text\n");
    gets(sentence);
    for(i=strlen(sentence)-1; i >=0; i--)
    putchar(sentence[i]);
    return 0;
}
Select one:
A. The sentence will get printed in same order as it entered
B. The sentence will get printed in reverse order
C. Half of the sentence will get printed
D. None of above
Correct Answer: B

Question 19
#include <stdio.h>
int main()
{
    int arr[10];
    // Assume that base address of arr is 4000 and size of integer
    // is 32 bit
    arr++;
    printf("%u", arr);
    return 0;
}
Select one:
A. 4020
B. 4002
C. lvalue required
D. 4004
Correct Answer: C
.
Question 20
What is the output of the following program?
int main()
{
    int i;
    int arr[4] = {0};
    for (i = 0; i <= 4; i++)
    printf("%d ", arr[i]);
    return 0;
}
Select one:
A. crash
B. prints 0 four times 1
C. Error
D. The program may print 0 four times followed by garbage value, or may crash if address (arr+5) is invalid.
Correct Answer: D




1 comment: