Showing posts with label Computer Programming. Show all posts
Showing posts with label Computer Programming. Show all posts

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


June 12, 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.

Questions:
1.
#include <stdio.h>
int main()
{int x; x = 5;        
                if(x > 5)x -= 5;
                else if(x >= 0)x += 00;
                else if(x)x += 5;
                else x -= 5;
                printf("%d\n",x);
                return 0;
}

Select one:

A. None of the above
B. 10
C. -5
D.  5
E.  6

The correct answer is: 5

2.
What is the output of the following code?
#include "stdio.h"
extern int a=5;
main(){
            void fun();
            printf("\n a=%d",a);
            fun();
            return 0;
            }
void fun()
{
            int a;
            printf(" in fun a=%d",a);
}

Select one:

A. a=0 in fun a=5
B. Error
C. None
D. a=5 in fun a=0

The correct answer is: a=5 in fun a=0

3.
What is the output of following program?
#include <stdio.h>
void abc(int a, int b)
{
            printf("%d%d",++a,++b);
            }
int main()
{
            int a=10;
            abc(++a,a++);
            abc(a++,++a);
            printf("%d",a);
            return 0;
}

Select one:

A. None
B. Error
C. 13 11 14 14 14
D. 13 11 14 15 14 

The correct answer is: 13 11 14 15 14

4.
What should be the output:
void main()
{
    int a = 10/3;
    printf("%d",a);
}

Select one:

A. 0
B. 3.0
C. 3.33
D. 3

The correct answer is:3

5.
#include <stdio.h>
int main()
{
                int i;
                if (printf("0"))
                    i = 3;
                else
                    i = 5;
                printf("%d", i);
                return 0;
}

Select one:

A. Error
B. 3
C. 03
D. None

The correct answer is: 03

6.
#include <stdio.h>
int main()
{
    int i = 0;
    switch (i)
    {
        case '0': printf("Hello");
                break;
        case '1': printf("world");
                break;

 default: printf("Helloworld");
    }
    return 0;
}

Select one:

A. Hello
B. Helloworld
C. None of these
D. world

The correct answer is: Helloworld

7.
What will be output of following program?
#include <stdio.h>
void convention(int,int,int);
int main()
{
    int a=5;   
    convention(a,++a,a++);
    return 0;
}
void  convention(int p,int q,int r)
{
    printf("%d %d %d",p,q,r);
}

Select one:

A. Error
B. None
C. 7 5 5
D. 7 7 5

The correct answer is: 7 7 5

8.#include<stdio.h>
void  main()
{    int a=15;   printf("%x", a);    getchar();  
}
Select one:
A. 15.0
B. 12
C. None of the above
D. f
E. c

The correct answer is: f

9.
What is the correct way to round off x, a float, to an int value?

Select one:
A. y=(int)(x+0.5)
B. y=(int)x+0.5
C. y=int(x+0.5)
D.  y=(int)(int)x+0.5)

The correct answer is: y=(int)(x+0.5)
10.
#include<stdio.h>
int main()
{
      int  i=10;
      printf("i=%d", i);
      {
            int  i=20;
                printf("i=%d", i);
                i++;
                printf("i=%d", i);
 }
      printf("i=%d", i);
      return 0;
}
Select one:
A. 10,10,20,21
B. None
C. Error
D. 10,20,21,10

The correct answer is:  10,20,21,10