AmbitionBox

Discover Best Places to work in India

C Programming

C Programming Questions and Answers

Showing 1 - 10 of 103 questions

1

What is the output of the program given below ?

#includeint main()
{
    enum status { pass, fail, atkt};
    enum status stud1, stud2, stud3;
    stud1 = pass;
    stud2 = atkt;
    stud3 = fail;
    printf("%d, %d, %d\n", stud1, stud2, stud3);
    return0;
}
a

0, 1, 2

b

1, 2, 3

c

0, 2, 1

d

1, 3, 2

correct answer c

Answer:Option C

Explanation :

enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2
stud1 = pass (value is 0)
stud2 = atkt (value is 2)
stud3 = fail (value is 1)
Hence it prints 0, 2, 1

2

What will be the output of the program in 16 bit platform (Turbo C under DOS)?

#includeint main()
{
    externint i;
    i = 20;
    printf("%d\n", sizeof(i));
    return0;
}
a

2

b

4

c

vary from compiler

d

Linker Error : Undefined symbol 'i'

correct answer d

Answer:Option D
Explanation :
Linker Error : Undefined symbol 'i'
The statement extern int i specifies to the compiler that the memory for 'i' is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name 'i' is available in any other program with memory space allocated for it. Hence a linker error has occurred.

3

Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

a

rem = 3.14 % 2.1;

b

rem = modf(3.14, 2.1);

c

rem = fmod(3.14, 2.1);

d

Remainder cannot be obtain in floating point division.

correct answer c
Answer:Option C
Explanation :

fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point divisions.
Example:
#include #include int main ()
{
  printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) );
  return0;
}
Output:
fmod of 3.14/2.1 is 1.040000
4

 What are the types of linkages?

a

Internal and External

b

External and None

c

External, Internal and None

d

Internal

correct answer c

Answer:Option C

Explanation :

External Linkage-> means global, non-static variables and functions.
Internal Linkage-> means static variables and functions with file scope.
None Linkage-> means Local variables.

5

Which of the following special symbol allowed in a variable name?

a

* (asterisk)

b

| (pipeline)

c

- (hyphen)

d

_ (underscore)

correct answer d

Answer:Option D
Explanation :

Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit.
Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=> foo_bar
=> _foo42
=> _
=> QuUx

6

Which of the following is not user defined data type?

1 :
struct book
{
    char name[10];
    float price;
    int pages;
};
2 :
longint l = 2.35;
3 :
enum day {Sun, Mon, Tue, Wed};
a

1

b

2

c

3

d

1 & 2

correct answer

Answer:Option B

Explanation :

C data types classification are

    Primary data types
       1. int
       2.char
       3. float
       4. double
       5.void
    Secondary data types (or) User-defined data type
       1. Array
       2. Pointer
       3. Structure
       4. Union
       5. Enum

So, clearly long int l = 2.35; is not User-defined data type.
(i.e.long int l = 2.35; is the answer.)

7

What is the output of the program?

#includeint main()
{
    int x = 10, y = 20, z = 5, i;
    i = x < y < z;
    printf("%d\n", i);
    return0;
}
a

0

b

1

c

Error

d

No Error

correct answer b

Answer:Option B

Explanation :

Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to be TRUE. The 1 is assigned to i.

8

What is the output of the program?

#includeint main()
{
    externint fun(float);
    int a;
    a = fun(3.14);
    printf("%d\n", a);
    return0;
}
int fun(int aa)
{
    return (int)++aa;
}
a

0

b

3

c

4

d

Compile Error

correct answer d

Answer:Option D
Explanation :
2 Errors
1. Type mismatch in redeclaration of fun
2. Type mismatch in parameter aa

9

What is the output of the program?

#include
int main()
{
    int a[5] = {2, 3};
    printf("%d, %d, %d\n", a[2], a[3], a[4]);
    return 0;
}

a

Garbage Values

b

2, 3, 3

c

3, 2, 2

d

0, 0, 0

correct answer d

Answer: Option D

Explanation :

When an automatic array is partially initialized, the remaining elements are initialized to 0.

10

In the following program how long will the for loop get executed?

#include
int main()
{
    int i=5;
    for(;scanf("%s", &i); printf("%d\n", i));
    return 0;
}

a

The for loop would not get executed at all

b

The for loop would get executed only once

c

The for loop would get executed 5 times

d

The for loop would get executed infinite times

correct answer d

Answer:Option D

Explanation :

During the for loop execution scanf() ask input and then printf() prints that given input. This process will be continued repeatedly because, scanf() returns the number of input given, the condition is always true(user gives a input means it reurns '1').
Hence this for loop would get executed infinite times.

Select a company to compare with

vs

Similar Companies