What will happen when the following code is executed?
void main()
{
char arr1[] = "REGALINT";
char *arr2;
arr2 = arr1;
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
void main()
{
char arr1[] = "REGALINT";
char *arr2;
arr2 = arr1;
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
a. 1,1
b. 1,4
c. 8,8
d. 8,9
d. 8,9
e. 9,4
Consider the following code
int i = 4, *j, *k;
Which one of the following statements will not work?
int i = 4, *j, *k;
Which one of the following statements will not work?
a. j = &i;
b. j = j + 4;
c. j = j - 2;
d. k = j + 3;
e. j = j * 2;
Which function will convert a string into a double precision quantity?
a. atoi()
b. atof()
c. atol()
d. atan()
e. acos()
Which file header is to be included for file handling in a C program?
a. string.h
b. file.h
c. stdio.h
d. stdlib.h
e. ctype.h
What will be printed on the standard output as a result of the following code snippet?
void main()
{
int num1 = 30, num2 = 4;
float result;
result = (float)(num1/num2);
printf("%.2f", result);
return 0;
}
void main()
{
int num1 = 30, num2 = 4;
float result;
result = (float)(num1/num2);
printf("%.2f", result);
return 0;
}
a. 7
b. 7.00
c. 7.000000
d. 7.5
e. 7.50
In which area of memory are static variables allocated?
a. stack
b. heap
c. With the code binary
d. None of the above
Which of the following is a function for formatting data in memory?
a. sprintf()
b. printf()
c. scanf()
d. free()
e. atol()
What would be printed on the standard output as a result of the following code snippet?
main()
{
void addup (int b);
addup(b);
return 0;
}
int b = 5;
void addup (int b)
{
static int v1;
v1 = v1+b;
printf("%d ", v1);
}
main()
{
void addup (int b);
addup(b);
return 0;
}
int b = 5;
void addup (int b)
{
static int v1;
v1 = v1+b;
printf("%d ", v1);
}
a. Will result in Compilation Error
b. 5
c. 0
d. Undefined value
Which function will you use to write a formatted output to the file?
a. fputc()
b. fputs()
c. fprintf()
d. fseek()
e. ftell()
Read the following two declaration statements.
1. #include <stdio.h>
2. #include "stdio.h"
Which of the following statements pertaining to the above two statements are correct?
1. #include <stdio.h>
2. #include "stdio.h"
Which of the following statements pertaining to the above two statements are correct?
a. For statement 1, the header file will be searched first in the local directory and then in the standard system directories such as "/usr/include"
b. For statement 1, the header file will be searched in the standard system directories such as "/usr/include"
c. For statement 2, the header file will be searched first in the local directory and then in the standard system directories such as "/usr/include"
d. For statement 2, the header file will be searched in the standard system directories such as "/usr/include"
e. None of the above
The declaration int (*p[5])() means:
a. p is an array of pointers to functions the return type of which is an integer
b. p is a pointer to a function that returns a pointer to an integer
c. p is a pointer to an array of integers
d. p is a pointer to an array of integer pointers
e. p is a pointer to a character string
What would be printed on the standard output as a result of the following code snippet?
#define Name Manish
main()
{
printf("My name""Name");
}
#define Name Manish
main()
{
printf("My name""Name");
}
a. My name Manish
b. My nameName
c. Results in Compilation Error
d. None of the above
What will be printed on the standard output as a result of the following code snippet?
void main()
{
int arr[5]={1,2,3,4,5};
printf("%d\n", *(arr+4));
}
void main()
{
int arr[5]={1,2,3,4,5};
printf("%d\n", *(arr+4));
}
a. 1
b. 2
c. 4
d. 5
e. Cannot be determined
What would be printed on the standard output as a result of the following code snippet?
main()
{
char *s="Hello World";
char s1[20], s2[20];
int len = sscanf(s,"%s",s1);
printf("%s : %d", s1, len);
}
main()
{
char *s="Hello World";
char s1[20], s2[20];
int len = sscanf(s,"%s",s1);
printf("%s : %d", s1, len);
}
a. Compilation Error
b. Hello World : 11
c. Hello World : 1
d. Hello : 5
e. Hello : 1
By which file function you can position the file pointer in accordance with the current position?
a. ftell()
b. fseek()
c. fgetc()
d. fread()
e. fscanf()
Read the statement below:
extern int a;
Which of the following statement/s pertaining to the above statement is/are correct?
extern int a;
Which of the following statement/s pertaining to the above statement is/are correct?
a. Declares an integer variable a; Allocates storage for the variable
b. Declares an integer variable a; Does not allocate the storage for the variable
c. Indicates that the variable is defined outside the current file
d. Brings the scope of the variable defined outside the file to this file
e. All of the above
f. None of the above
Which of the following is/are the correct signature/s of main with command line arguments?
a. int main(int argc, char **argv)
b. int main(int argc, char *argv[])
c. int main(int argc, char *argv)
d. int main(int argc, char argv[])
e. All of the above
What would be printed on the standard output as a result of the following code snippet?
main()
{
enum {red, green, blue = 0, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
main()
{
enum {red, green, blue = 0, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
a. Will result in Compilation Error
b. 0 1 2 3
c. 0 1 0 1
d. 0 1 0 2
e. Undefined
What would be printed on the standard output as a result of the following code snippet?
#include<stdio.h>
main()
{
unsigned char a=255;
a = a+1;
printf("%d",a);
return 0;
}
#include<stdio.h>
main()
{
unsigned char a=255;
a = a+1;
printf("%d",a);
return 0;
}
a. Undefined value
b. 256
c. 1
d. 0
e. -1
Identify the incorrect statement
a. Records can be defined in C by using structures
b. Structure members can be of the same/different data types
c. Memory is reserved when a structure label is defined
d. A pointer to a structure can be used to pass a structure to a function
e. Arrays of structures can be defined and initialized
What would be printed on the standard output as a result of the following code snippet?
#define max(a, b)((a) > (b)?(a):(b))
main()
{
int a=4, c = 5;
printf("%d ", max(a++, c++));
printf("%d %d\n", a,c);
}
#define max(a, b)((a) > (b)?(a):(b))
main()
{
int a=4, c = 5;
printf("%d ", max(a++, c++));
printf("%d %d\n", a,c);
}
a. Results in Compilation Error
b. 6 4 5
c. 6 5 7
d. 6 5 6
e. None of the above
Given the array:
int num[3][4]=
{
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
what would be the output of *(*(num+1))?
int num[3][4]=
{
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
what would be the output of *(*(num+1))?
a. 3
b. 15
c. 66
d. 6
e. 25
An array is defined with the following statement in a file, file1.c
int a[ ] = { 1, 2, 3, 4, 5, 6 };
In another file, file2.c, the following code snippet is written to use the array a:
extern int a[];
int size = sizeof(a);
What is wrong with the above code snippet?
int a[ ] = { 1, 2, 3, 4, 5, 6 };
In another file, file2.c, the following code snippet is written to use the array a:
extern int a[];
int size = sizeof(a);
What is wrong with the above code snippet?
a. The size of the operator cannot be applied to an array
b. There is nothing wrong with the code snippet. The value of the size will be 6
c. There is nothing wrong with the code snippet. The value of the size will be 7
d. An extern array of unspecified size is an incomplete type. The size of the operator during compile time is unable to learn the size of an array that is defined in another file
e. None of the above
What would be printed on the standard output as a result of the following code snippet?
main()
{
int u = 1, v = 3;
printf("%d %d",u,v);
funct1(&u,&v);
printf("%d %d\n",u,v);
}
void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
main()
{
int u = 1, v = 3;
printf("%d %d",u,v);
funct1(&u,&v);
printf("%d %d\n",u,v);
}
void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
a. 1 31 3
b. 1 3 1 1
c. 1 30 0
d. 1 1 1 1
e. 3 1 3 1
Given the following array:
char books[][40]={
"The Little World of Don Camillo",
"To Kill a Mockingbird",
"My Family and Other Animals",
"Birds, Beasts and Relatives"
};
char books[][40]={
"The Little World of Don Camillo",
"To Kill a Mockingbird",
"My Family and Other Animals",
"Birds, Beasts and Relatives"
};
What would be the output of printf("%s",books[3]);?
a. Birds
b. B
c. Birds, Beasts and Relatives
d. My Family and Other Animals
e. M
Given the following array declaration:
int a[2][3][4]
int a[2][3][4]
What would be the number of elements in array a?
a. 24
b. 22
c. 20
d. 12
e. 36
What would be printed on the standard output as a result of the following code snippet?
int Recur(int num)
{
if(num==1 || num==0)
return 1;
if(num%2==0)
return Recur(num/2)+2;
else
return Recur(num-1)+3;
}
int main()
{
int a=9;
printf("%d\n", Recur(a));
return 0;
}
int Recur(int num)
{
if(num==1 || num==0)
return 1;
if(num%2==0)
return Recur(num/2)+2;
else
return Recur(num-1)+3;
}
int main()
{
int a=9;
printf("%d\n", Recur(a));
return 0;
}
a. 10
b. 9
c. 11
d. 8
e. None of the above
What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr1[] = "REGALINT";
printf("%d,",strlen(arr1));
printf("%d",sizeof(arr1));
}
void main()
{
char arr1[] = "REGALINT";
printf("%d,",strlen(arr1));
printf("%d",sizeof(arr1));
}
a. 1,1
b. 8,4
c. 8,8
d. 8,9
e. 9,8
What is the return type of the following function declaration?
func(char c);
func(char c);
a. void
b. char
c. int
d. undefined
What would be printed on the standard output as a result of the following code snippet?
char *str1 = "Hello World";
strcat(str1, '!');
printf("%s", str1);
char *str1 = "Hello World";
strcat(str1, '!');
printf("%s", str1);
a. Hello World!
b. Hello World
c. Hello
d. The code snippet will throw a compilation error
What would be printed on the standard output as a result of the following code snippet?
main()
{
int arr[10];
int a = sizeof(arr);
printf("%d\n",a);
return 0;
}
main()
{
int arr[10];
int a = sizeof(arr);
printf("%d\n",a);
return 0;
}
a. Compilation Error
b. 10
c. 4
d. 40
e. 0
Suppose there is a file a.dat which has to be opened in the read mode using the FILE pointer ptr1, what will be the correct syntax?
a. ptr1 = open("a.dat");
b. ptr1 = fileopen("a.dat");
c. ptr1 = fopen("a.dat","r");
d. ptr1 = open("a.dat","r");
e. ptr1 = fileopen("a.dat","r");
If a two dimensional array arr[4][10](an array with 4 rows and 10 columns) is to be passed in a function, which of the following would be the valid parameters in the function definition?
a. fn(int arr[4][10])
b. fn(int arr[][10])
c. fn(int arr[4][])
d. fn(int (*fn)[13])
e. None of the above
What is the function to concatenate two strings?
a. strcmp()
b. strcpy()
c. strcat()
d. strlen()
e. catstr()
What would be printed on the standard output as a result of the following code snippet?
main()
{
int n=5, x;
x = n++;
printf("%d ", x);
x = ++n;
printf("%d ", x++);
printf("%d", x);
return 0;
}
main()
{
int n=5, x;
x = n++;
printf("%d ", x);
x = ++n;
printf("%d ", x++);
printf("%d", x);
return 0;
}
a. 6 7 8
b. 5 7 8
c. 6 8 8
d. 5 8 8
e. None of the above
Which of the following is the correct way of initializing a two-dimensional array?
a. char str[2][4]={ "abc", "def" };
b. char str[2][4]={ {"abc"}, {"def"} };
c. char str[2][4]={ {'a','b','c','\0'}, {'d','e','f','\0'} };
d. a and b
e. a, b and c
What does the argv[0] represent?
a. The first command line parameter has been passed to the program
b. The program name
c. The number of command line arguments
d. None of the above
Which of the following is not a relational operator?
a. ==
b. !=
c. <>
d. >=
e. <=
Which of the following statements is/are valid and correct?
1.char amessage[] = "lmnop";
amessage++;
2.char *pmessage = "abcde";
(*pmessage)++;
3.char amessage[] = "lmnop";
(*amessage)++;
4.char *pmessage = "abcde";
pmessage++;
a. 1234
b. 23
c. 24
d. 14
e. 34
Given the array:
int num[3][4]= {
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
int num[3][4]= {
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
What would be the output of *(*(num+1)+1)+1?
a. 3
b. 15
c. 26
d. 66
e. 77
What will happen when the following code is executed?
{
int num;
num =0;
do {-- num;
printf("%d\n", num);
num++;
} while (num >=0);
}
{
int num;
num =0;
do {-- num;
printf("%d\n", num);
num++;
} while (num >=0);
}
a. The loop will run infinitely
b. The program will not enter the loop
c. There will be a compilation error
d. A runtime error will be reported
Which of the following declarations of structures is/are valid?
1)
struct node {
int count;
char *word;
struct node next;
}Node;
2)
struct node {
int count;
char *word;
struct node *next;
}Node;
3)
struct node {
int count;
char *word;
union u1 {
int n1;
float f1;
}U;
}Node;
1)
struct node {
int count;
char *word;
struct node next;
}Node;
2)
struct node {
int count;
char *word;
struct node *next;
}Node;
3)
struct node {
int count;
char *word;
union u1 {
int n1;
float f1;
}U;
}Node;
a. 123
b. 12
c. 23
d. 2
e. None of the above
Which function returns the current pointer position within a file?
a. ftell()
b. fseek()
c. fgetc()
d. fread()
e. fscanf()
What would be printed on the standard output as a result of the following code snippet?
main()
{
signed char i = 1;
for (; i<=255; i++)
printf ("%d ",i);
return 0;
}
main()
{
signed char i = 1;
for (; i<=255; i++)
printf ("%d ",i);
return 0;
}
a. Compilation Error
b. 1 2 3 ... 255
c. 1 2 3 . . . 127
d. 1 2 3 . . . 127 -128 -127 ... 0 1 2 3 . . . (infinite times)
What would be printed on the standard output as a result of the following code snippet?
#define func(t, a, b) { t temp; temp=a; a=b; b=temp; }
main()
{
int a=3, b=4;
float c=4.5, d = 5.99;
func(int, a, b);
func(float, c, d);
printf("%d %d ", a, b);
printf("%.2f %.2f\n", c, d);
}
#define func(t, a, b) { t temp; temp=a; a=b; b=temp; }
main()
{
int a=3, b=4;
float c=4.5, d = 5.99;
func(int, a, b);
func(float, c, d);
printf("%d %d ", a, b);
printf("%.2f %.2f\n", c, d);
}
a. Results in Compilation Error
b. 3 4 5.99 4.50
c. 3 4 4.50 5.99
d. 4 3 5.99 4.50
e. None of the above
What does the following function do?
int fn(unsigned int x)
{
int count = 0;
for(; x!=0; x&=(x-1))
count++;
return count;
}
int fn(unsigned int x)
{
int count = 0;
for(; x!=0; x&=(x-1))
count++;
return count;
}
a. Returns the minimum number of bits required to represent the number x
b. Returns the number of zero bits present in the number x
c. Returns the number of 1 bits(bits having one) in the number x
d. Returns the square root of the number
e. None of the above
Given the following array:
int a[8] = {1,2,3,4,5,6,7,0};
what would be the output of
printf("%d",a[4]); ?
int a[8] = {1,2,3,4,5,6,7,0};
what would be the output of
printf("%d",a[4]); ?
a. 3
b. 4
c. 5
d. 6
e. 7
Which of the following standard functions is used to close a file?
a. fileclose()
b. closefile()
c. fclose()
d. Any of the above
What would be printed on the standard output as a result of the following code snippet?
main()
{
char option = 5;
switch(option)
{
case '5':
printf("case : 1 \n");
break;
case 5:
printf("case : 2 \n");
break;
default:
printf("case : 3 \n");
break;
}
return 0;
}
main()
{
char option = 5;
switch(option)
{
case '5':
printf("case : 1 \n");
break;
case 5:
printf("case : 2 \n");
break;
default:
printf("case : 3 \n");
break;
}
return 0;
}
a. case : 1
b. case : 2
c. case : 3
d. Result in compilation error
e. None of the above
Which of the following statements will result in a compilation error?
a. int n=5, x; x=n++;
b. int n=5, x; x= ++n++;
c. int n=5, x; x= (n+1)++;
d. int n=5, x=6; x= (n+x)++;
e. None of the above
From which of the following loop or conditional constructs, is "break" used for an early exit?
a. switch
b. for
c. while
d. do-while
e. All of the above
Which of the following is not a string function?
a. strlen()
b. strcmp()
c. strcpy()
d. strrev()
e. strcomp()
What will be printed on the standard output as a result of the following code snippet?
int funr(int x, int y)
{
if(x <= 0)
{
return y;
}
else
{
return (1+funr(x-1,y));
}
}
void main()
{
printf("%d",funr(2,3));
}
int funr(int x, int y)
{
if(x <= 0)
{
return y;
}
else
{
return (1+funr(x-1,y));
}
}
void main()
{
printf("%d",funr(2,3));
}
a. 2
b. 3
c. 5
d. 6
e. 9
Given the following array:
char books[][40]={
"The Little World of Don Camillo",
"To Kill a Mockingbird",
"My Family and Other Animals",
"Birds, Beasts and Relatives"
};
char books[][40]={
"The Little World of Don Camillo",
"To Kill a Mockingbird",
"My Family and Other Animals",
"Birds, Beasts and Relatives"
};
What would be the output of printf("%c",books[2][5]);?
a. m
b. M
c. F
d. i
e. L
Which of the following is not a type of operator?
a. Rational
b. Unary
c. Ternary
d. Compound assignment
e. Logical
Which header file are methods(or macros) isalpha(), islower() a part of?
a. stdio.h
b. ctype.h
c. string.h
d. math.h
e. None of the above
What would be printed on the standard output as a result of the following code snippet?
main()
{
enum {red, green, blue = 6, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
main()
{
enum {red, green, blue = 6, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
a. 0 1 6 2
b. 0 1 6 7
c. Will result in Compilation Error
d. None of the above
What will be printed on the standard output as a result of the following code snippet?
main()
{
int num = 425;
printf("%d", printf("%d", num));
}
main()
{
int num = 425;
printf("%d", printf("%d", num));
}
a. Will result in Compilation Error
b. 4425
c. 4253
d. 3435
e. None of the above
What would be printed on the standard output as a result of the following code snippet?
int b = 5;
main()
{
void addup (int b);
int i;
for(i=1; i<=5; i++)
addup(1);
return 0;
}
void addup (int b)
{
static int v1;
v1 = v1+b;
printf("%d ", v1);
}
int b = 5;
main()
{
void addup (int b);
int i;
for(i=1; i<=5; i++)
addup(1);
return 0;
}
void addup (int b)
{
static int v1;
v1 = v1+b;
printf("%d ", v1);
}
a. 1 2 3 4 5
b. 5 6 7 8 9
c. 5 5 5 5 5
d. 1 1 1 1 1
e. Undefined value
What is the return value in case a file is not opened successfully by using fopen()?
a. 0
b. 1
c. 100
d. NULL
What will be printed on the standard output as a result of the following code snippet?
void func()
{
static int i = 1;
int j = 1;
i++;
j++;
printf("%d %d ",i,j);
}
void main()
{
func();
func();
func();
}
void func()
{
static int i = 1;
int j = 1;
i++;
j++;
printf("%d %d ",i,j);
}
void main()
{
func();
func();
func();
}
a. 2 2 2 2 2 2
b. 2 2 3 2 4 2
c. 2 2 2 3 2 4
d. 2 2 3 3 4 4
e. None of these
Which is/are the type/s of memory allocation that needs/need the programmer to take care of memory management?
a. Static memory allocation
b. Dynamic memory allocation
c. Automatic memory allocation
d. Memory allocation on stack
e. Memory allocation on heap
What would be printed on the standard output as a result of the following code snippet?
char i = 'A';
char *j;
j = & i;
*j = *j + 32;
printf("%c",i);
char i = 'A';
char *j;
j = & i;
*j = *j + 32;
printf("%c",i);
a. An error will occur
b. a
c. A
d. b
e. c
Is the following statement correct? If not, why not? If yes, what is the size of the array?
int array[][3] = { {1,2}, {2,3}, {3,4,2} };
int array[][3] = { {1,2}, {2,3}, {3,4,2} };
a. Yes, the size is three columns by two rows
b. Yes, the size is two columns by two rows
c. No, the first dimension is omitted
d. No, one of the three initializer sets contains too many numbers
e. Yes, the size is three columns by three rows
Study the following code where num is an integer array and n is the length of the array:
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i] > num[j])
{
var=num[i];
num[i]=num[j];
num[j]=var;
}
}
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i] > num[j])
{
var=num[i];
num[i]=num[j];
num[j]=var;
}
}
}
What does the above code do?
a. It prints the elements of the array in the ascending order
b. It calculates the sum of the elements of the array
c. It sorts the array in the ascending order
d. It sorts the array in the descending order
e. It calculates the average of the elements of the array
Which function allocates memory and initializes elements to 0?
a. assign()
b. calloc()
c. malloc()
d. swab()
e. allocate()
Which of the following file modes would mean read + append?
a. w+
b. a+
c. r+
d. r+a
e. a+r
Which function will you use to position the file pointer at the beginning of the file?
a. rewind()
b. fseek()
c. fscanf()
d. a or b
e. b or c
What is wrong with the following statement?
int func();
int func();
a. The function definition {...} is missing
b. While calling a function, the type int is not needed
c. No parameter has been passed
d. The semicolon should not be there
e. There is nothing wrong with the statement
What would be printed on the standard output as a result of the following code snippet?
main()
{
int a[5] = {1,4,5,6,9};
printf("%d\t", *a); //Line 1
printf("%d", *++a); //Line 2
return 0;
}
main()
{
int a[5] = {1,4,5,6,9};
printf("%d\t", *a); //Line 1
printf("%d", *++a); //Line 2
return 0;
}
a. 1 4
b. 0 1
c. Undefined value
d. Compilation Error in "Line 1"
e. Compilation Error in "Line 2"
What will be the output of the following program?
#include <assert.h>
main()
{
int n = 5;
assert(n > 3); //statement 1
n = n+2;
assert(n > 7);//statement 2
return 0;
}
#include <assert.h>
main()
{
int n = 5;
assert(n > 3); //statement 1
n = n+2;
assert(n > 7);//statement 2
return 0;
}
a. Assertion 'n > 3' failed; Program aborts at statement 1
b. Assertion 'n > 7' failed; Program aborts at statement 2
c. Program returns 0 with the value of n as 7
d. Compilation Error
Which of the following comparison statements will be true if an integer is 16 bits and a long is 32 bits on a machine?
a. -1L < 1U
b. -1L > 1U
c. -1L < 1UL
d. -1L > 1UL
Given the operators:
1) *
2) /
3) %
What would be the order of precedence?
1) *
2) /
3) %
What would be the order of precedence?
a. 1,2,3
b. 1,3,2
c. 3,2,1
d. All have the same precedence
e. 1 and 2 have the same precedence, 3 is of lower precedence
What will be printed on the standard output as a result of the following code snippet?
void main()
{
int arr[][2] = {1,2,3,4,5,6};
printf("%d",arr[2][1]);
}
void main()
{
int arr[][2] = {1,2,3,4,5,6};
printf("%d",arr[2][1]);
}
a. 2
b. 3
c. 4
d. 5
e. 6
Which of the following is the correct way of initializing a two-dimensional array?
a. char str[2][4]={
"abc",
"def"
};
"abc",
"def"
};
b. char str[2][4]={
{"abc"},
{"def"}
};
{"abc"},
{"def"}
};
c. char str[2][4]={
{'a','b','c','\0'},
{'d','e','f','\0'}
};
{'a','b','c','\0'},
{'d','e','f','\0'}
};
d. a and b
e. a, b and c
Study the following code:
int n = 2;
int a[n];
What is the error in the above code?
int n = 2;
int a[n];
What is the error in the above code?
a. There is no error
b. The minimum limit of an array is 5
c. The second statement should be placed before the first
d. A constant value has to be given in place of a variable for array declaration
Which of the following is not a file related function?
a. fgetc()
b. puts()
c. fputc()
d. fscanf()
e. fprintf()
The declaration int *(*p)[10] indicates:
a. p is an array of pointers to functions the return type of which is an integer
b. p is a pointer to a function that returns a pointer to an integer
c. p is a pointer to an array of integer pointers
d. p is a pointer to a character string
Which of the following is not a storage type?
a. auto
b. global
c. static
d. register
e. extern
Which of the following sets of conversion statements may result in the loss of data?
a. int i;
char c;
i=c;
c=i;
char c;
i=c;
c=i;
b. int i;
char c;
c=i;
i=c;
char c;
c=i;
i=c;
c. int i;
float f;
i=f;
f=i;
float f;
i=f;
f=i;
d. None of the above
What is the error in the following statement where str is a character array and the statement is supposed to traverse through the whole character string str?
for(i=0;str[i];i++)
for(i=0;str[i];i++)
a. There is no error
b. There should be no semi colon after the statement
c. The condition should be str[i] != '\0'
d. The condition should be str[i] != NULL
e. i should be initialized to 1
What happens when the continue keyword is encountered in the 'for loop'?
a. Control passes to the initialization of the loop
b. Control passes to the condition of the loop
c. Control passes to the beginning of the loop
d. Control passes to the first statement of the loop
e. Control passes to the statement preceding the end of the loop
Which of the following functions is used to extract formatted input from a file?
a. fputc()
b. fputs()
c. fprintf()
d. fscanf()
e. ftell()
What would be printed on the standard output as a result of the following code snippet?
void main()
{
unsigned char a=25;
a = ~a;
signed char b = 25;
b = ~b;
printf("%d %d ", a, b);
}
void main()
{
unsigned char a=25;
a = ~a;
signed char b = 25;
b = ~b;
printf("%d %d ", a, b);
}
a. 0 0
b. 230 230
c. 230 -26
d. 230 -103
e. None of the above
Select the correct statement about arrays
a. Automatic arrays cannot be initialized
b. An array declared as A[100][100] can hold a maximum of 10000 elements
c. An array can hold elements of different data types
Which of the following statements are correct for the keyword register?
a. It is a storage-class-specifier
b. It guarantees that the variable is kept in the CPU register for maximum speed
c. It requests that the variable be kept in the CPU register for maximum speed
d. It does not guarantee that the variable value is kept in CPU register for maximum speed
Consider the following code.
int i = 4, *j, *k;
Which one of the following statements will not work?
int i = 4, *j, *k;
Which one of the following statements will not work?
a. j = &i;
b. j = j + 4;
c. j = j - 2;
d. k = j + 3;
e. j = j * 2;
In order to read structures/records from a file, which function will you use?
a. fscanf()
b. fread()
c. fgets()
d. fgetc()
e. fseek
Suppose there is a file a.dat which has to be opened in the read mode using the FILE pointer ptr1, what will be the correct syntax?
a. ptr1 = open("a.dat");
b. ptr1 = fileopen("a.dat");
c. ptr1 = fopen("a.dat","r");
d. ptr1 = open("a.dat","r");
e. ptr1 = fileopen("a.dat","r");
What will happen if you assign a value to an element of an array the subscript of which exceeds the size of the array?
a. The element will be set to 0
b. Nothing; it is commonly done
c. It is undefined behavior
d. You will get an error message from the compiler
Which of the following is not a relational operator?
a. ==
b. !=
c. <>
d. >=
e. <=
What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr[] = {'R','A','M','\0'};
printf("%d",strlen(arr));
}
void main()
{
char arr[] = {'R','A','M','\0'};
printf("%d",strlen(arr));
}
a. 0
b. 1
c. 3
d. 4
e. Cannot be determined
What will be printed on the standard output as a result of the following code snippet?
void main()
{
int i,j,k;
i=4;
j=30;
k=0;
k=j++/i++;
++k;
printf("%d %d %d",i,j,k);
}
void main()
{
int i,j,k;
i=4;
j=30;
k=0;
k=j++/i++;
++k;
printf("%d %d %d",i,j,k);
}
a. 5 31 8
b. 5 31 7
c. 5 31 6
d. 4 30 7
Which standard function is used to clear memory allocated by the malloc() function?
a. free
b. calloc
c. delete
d. release
e. destroy
What would be printed on the standard output as a result of the following code snippet?
main()
{
char *pmessage = "asdfgh";
*pmessage++;
printf("%s", pmessage);
return 0;
}
main()
{
char *pmessage = "asdfgh";
*pmessage++;
printf("%s", pmessage);
return 0;
}
a. Will result in Compilation Error
b. Undefined string
c. sdfgh
d. asdfgh
Which of the following is not a valid mode for opening a file?
a. r
b. w
c. a
d. r+
e. i
What would be printed on the standard output as a result of the following code snippet?
main( )
{
char *str[ ] = {
"Manish"
"Kumar"
"Choudhary"
};
printf ( "\nstring1 = %s", str[0] );
printf ( "\nstring2 = %s", str[1] );
printf ( "\nstring3 = %s", str[2] );
}
main( )
{
char *str[ ] = {
"Manish"
"Kumar"
"Choudhary"
};
printf ( "\nstring1 = %s", str[0] );
printf ( "\nstring2 = %s", str[1] );
printf ( "\nstring3 = %s", str[2] );
}
a. string1 = Manish
string2 = Kumar
string3 = Choudhary
string2 = Kumar
string3 = Choudhary
b. string1 = Manish
string2 = Manish
string3 = Manish
string2 = Manish
string3 = Manish
c. string1 = ManishKumarChoudhary
string2 = (null)
string3 = (null)
string2 = (null)
string3 = (null)
d. You will get an error message from the compiler
What is the output of the following program ?
main()
{
int u = 1, v = 3;
printf("%d %d",u,v);
funct1(&u,&v);
printf(" %d %d\n",u,v);
}
void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
main()
{
int u = 1, v = 3;
printf("%d %d",u,v);
funct1(&u,&v);
printf(" %d %d\n",u,v);
}
void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
a. 1 3 1 3
b. 1 3 1 1
c. 1 3 0 0
d. 1 1 1 1
e. 3 1 3 1
What would be printed on the standard output as a result of the following code snippet?
#define max(a, b) ((a) > (b)?(a):(b))
main()
{
int a=4;
float b=4.5;
printf("%.2f\n",max(a, b));
}
#define max(a, b) ((a) > (b)?(a):(b))
main()
{
int a=4;
float b=4.5;
printf("%.2f\n",max(a, b));
}
a. Results in Compilation Error
b. Undefined value
c. 4.50
d. 4.0
e. None of the above
What is wrong with the following function protoype statement?
int func();
int func();
a. The function definition {...} is missing
b. While calling a function, the type int is not needed
c. No parameter has been passed
d. The semicolon should not be there
e. There is nothing wrong with the statement
What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr[] = {'R','A','M'};
printf("%d",strlen(arr));
}
void main()
{
char arr[] = {'R','A','M'};
printf("%d",strlen(arr));
}
a. 0
b. 1
c. 3
d. 4
e. Cannot be determined
What will be the output of the following program, assuming that data type short takes 2 bytes for storage?
struct node
{
unsigned char bit1 : 1;
unsigned char bit2 : 1;
unsigned short bit3 : 7;
} node1;
main()
{
int size = sizeof(node1);
printf("%d", size);
}
struct node
{
unsigned char bit1 : 1;
unsigned char bit2 : 1;
unsigned short bit3 : 7;
} node1;
main()
{
int size = sizeof(node1);
printf("%d", size);
}
a. 4
b. 3
c. 2
d. None of the above
What would be printed on the standard output as a result of the following code snippet?
main()
{
int i=5;
char option = 5;
switch(option)
{
case '5':
printf("case : 1 \n");
break;
case i:
printf("case : 2 \n");
break;
default:
printf("case : 3 \n");
break;
}
return 0;
}
main()
{
int i=5;
char option = 5;
switch(option)
{
case '5':
printf("case : 1 \n");
break;
case i:
printf("case : 2 \n");
break;
default:
printf("case : 3 \n");
break;
}
return 0;
}
a. case : 1
b. case : 2
c. case : 3
d. Result in compilation error
e. None of the above
Which standard function is used to deallocate memory allocated by the malloc() function?
a. free
b. calloc
c. delete
d. release
e. destroy
Consider the following code.
int i = 4, *j, *k;
Which one of the following statements will result in Compilation error?
int i = 4, *j, *k;
Which one of the following statements will result in Compilation error?
a. j = &i;
b. j = j + 4;
c. j = j - 2;
d. k = j + 3;
e. j = j * 2;
Which function will convert a string into an integer?
a. int()
b. number()
c. atoi()
d. val()
e. tonum()
What will be the output of following code?
int main()
{
int i;
i = 0;
for (i = 1; i <2; i++)
{
i++;
printf( "%d", i );
continue;
printf( "%d", i );
}
return 0;
}
int main()
{
int i;
i = 0;
for (i = 1; i <2; i++)
{
i++;
printf( "%d", i );
continue;
printf( "%d", i );
}
return 0;
}
a. 22
b. 2,2
c. 2
d. None of the above
Which of the following sets of conversion statements may result in the loss of data?
a. int i;
char c;i=c;c=i;
char c;i=c;c=i;
b. int i;char c;c=i;i=c;
c. int i;float f;i=f;f=i;
d. None of the above
What will happen when the following code is executed?
void main()
{
char arr1[] = "REGALINT";
char arr2[4] = "REGALINT";
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
void main()
{
char arr1[] = "REGALINT";
char arr2[4] = "REGALINT";
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
a. 1,1
b. 1,4
c. 8,8
d. 8,9
e. 9,4
What will be the output of the following program?
#include <assert.h>
main()
{
int n = 5;
assert(n > 3); //statement 1
n = n+2;
assert(n > 7);//statement 2
return 0;
}
#include <assert.h>
main()
{
int n = 5;
assert(n > 3); //statement 1
n = n+2;
assert(n > 7);//statement 2
return 0;
}
a. Assertion 'n > 3' failed; Program aborts at statement 1
b. Assertion 'n > 7' failed; Program aborts at statement 2
c. Program returns 0 with the value of n as 7
d. Compilation Error
What would be printed on the standard output as a result of the following code snippet?
main()
{
int a[5] = {1,4,5,6,9};
printf("%d\t", *a); //Line 1
printf("%d", *++a); //Line 2
return 0;
}
main()
{
int a[5] = {1,4,5,6,9};
printf("%d\t", *a); //Line 1
printf("%d", *++a); //Line 2
return 0;
}
a. 1 4
b. 0 1
c. Undefined value
d. Compilation Error in "Line 1"
e. Compilation Error in "Line 2"
Which of the following comparison statements will be true if an integer is 16 bits and a long is 32 bits on a machine?
a. -1L < 1U
b. -1L > 1U
c. -1L < 1UL
d. -1L > 1UL
What will happen when the following code is executed?
void main()
{
char arr1[] = "REGALINT";
char arr2[10] = "REGALINT";
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
void main()
{
char arr1[] = "REGALINT";
char arr2[10] = "REGALINT";
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
a. 1,1
b. 1,4
c. 8,8
d. 8,9
e. 9,10
Which of the following statements is valid and correct?
a. char amessage[] = "lmnop";
amessage++;
amessage++;
b. char *pmessage = "abcde";
(*pmessage)++;
(*pmessage)++;
c. char amessage[] = "lmnop";
(*amessage)++;
(*amessage)++;
d. char *pmessage = "abcde";
pmessage++;
pmessage++;
What is wrong with the following function prototype statement?
int func();
int func();
a. The function definition {...} is missing
b. While calling a function, the type int is not needed
c. No parameter has been passed
d. The semicolon should not be there
e. There is nothing wrong with the statement
This comment has been removed by the author.
ReplyDeletePlaynGo Casino 2021 | Deposit and withdraw winnings - Dr.MCD
ReplyDeletePlaynGo Casino 평택 출장샵 is an online 김포 출장샵 casino that is the top of our 수원 출장안마 list. Its 춘천 출장안마 design and quality have been demonstrated by the use of 보령 출장마사지 different software,