Would you like to submit the test?

C Language Questions And Answers Sample Test 3


Sample C Language Test 3 for you to Practice. Evaluate your C Language Test 3 test answering skills by trying the online C Language Sample Test 3 and know your score.

C Language Test 3


You have scored 3 out of 10
You Scored:2
Total Questions:2
Attended Questions:2
Correct Answered:2
1.
What will be the output of the program?

#include<stdio.h>
#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()
{
    int i=10, j=5, k=0;
    k = MAN(++i, j++);
    printf("%d, %d, %dn", i, j, k);
    return 0;
}



Explanation:

The macro MAN(x, y) ((x)>(y)) ? (x):(y); returns the biggest number of given two numbers.

Step 1: int i=10, j=5, k=0; The variable i, j, k are declared as an integer type and initialized to value 10, 5, 0 respectively.

Step 2: k = MAN(++i, j++); becomes,

=> k = ((++i)>(j++)) ? (++i):(j++);

=> k = ((11)>(5)) ? (12):(6);

=> k = 12

Step 3: printf("%d, %d, %dn", i, j, k); It prints the variable i, j, k.

In the above macro step 2 the variable i value is increemented by 2 and variable j value is increemented by 1.

Hence the output of the program is 12, 6, 12


2.      A pointer is





3. How many bytes are occupied by near, far and huge pointers (DOS)?



Explanation:

near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4 bytes long.


4.
What will be the output of the program?

#include<stdio.h>
#define FUN(i, j) i##j

int main()
{
    int va1=10;
    int va12=20;
    printf("%dn", FUN(va1, 2));
    return 0;
}



Explanation:

The following program will make you understand about ## (macro concatenation) operator clearly.


5.
What will be the output of the program?

#include<stdio.h>

int main()
{
    const int x=5;
    const int *ptrx;
    ptrx = &x;
    *ptrx = 10;
    printf("%dn", x);
    return 0;
}



Explanation:

Step 1: const int x=5; The constant variable x is declared as an integer data type and initialized with value '5'.

Step 2: const int *ptrx; The constant variable ptrx is declared as an integer pointer.

Step 3: ptrx = &x; The address of the constant variable x is assigned to integer pointer variable ptrx.

Step 4: *ptrx = 10; Here we are indirectly trying to change the value of the constant vaiable x. This will result in an error.

To change the value of const variable x we have to use *(int *)&x = 10;


6.
Which of the following statements are correct about an array?
1: The array int num[26]; can store 26 elements.
2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration.
4: The declaration num[SIZE] is allowed if SIZE is a macro.





7.
What will be the output of the program?

#include<stdio.h>
int get();

int main()
{
    const int x = get();
    printf("%d", x);
    return 0;
}
int get()
{
    return 20;
}



Explanation:

Step 1: int get(); This is the function prototype for the funtion get(), it tells the compiler returns an integer value and accept no parameters.

Step 2: const int x = get(); The constant variable x is declared as an integer data type and initialized with the value "20".

The function get() returns the value "20".

Step 3: printf("%d", x); It prints the value of the variable x.

Hence the output of the program is "20".


8.
     What will be the output of the program?

#include
typedef void v;
typedef int i;

int main()
{
    v fun(i, i);
    fun(2, 3);
    return 0;
}
v fun(i a, i b)
{
    i s=2;
    float i;
    printf("%d,", sizeof(i));
    printf(" %d", a*b*s);
}





9.
    What do the following declaration signify?

char *scr;





10.
What will be the output of the program in Turb C (under DOS)?

#include<stdio.h>

int main()
{
    int arr[5], i=0;
    while(i<5)
        arr[i]=++i;

    for(i=0; i<5; i++)
        printf("%d, ", arr[i]);

    return 0;
}





11.
In which stage the following code 
#include<stdio.h> 
gets replaced by the contents of the file stdio.h



Explanation:

The preprocessor replaces the line #include <stdio.h> with the system header file of that name. More precisely, the entire text of the file 'stdio.h' replaces the #include directive.


12.
What will be the output of the program?

#include<stdio.h>
int fun(int **ptr);

int main()
{
    int i=10;
    const int *ptr = &i;
    fun(&ptr);
    return 0;
}
int fun(int **ptr)
{
    int j = 223;
    int *temp = &j;
    printf("Before changing ptr = %5xn", *ptr);
    const *ptr = temp;
    printf("After changing ptr = %5xn", *ptr);
    return 0;
}





13. What would be the equivalent pointer expression for referring the array element a[i][j][k][l]





14.
What will be the output of the program ?

#include<stdio.h>

int main()
{
    int arr[1]={10};
    printf("%dn", 0[arr]);
    return 0;
}





15.
What does the following declaration mean?
int (*ptr)[10];





16.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?

#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
    int x=10, y=20;
    SWAP(x, y, int);
    printf("%d %dn", x, y);
    return 0;
}



Explanation:

The code won't compile since declaration of t cannot occur within parenthesis.


17.
Declare the following statement?
"An array of three pointers to chars".





18.
What will be the output of the program ?

#include<stdio.h>

int main()
{
    void fun(int, int[]);
    int arr[] = {1, 2, 3, 4};
    int i;
    fun(4, arr);
    for(i=0; i<4; i++)
        printf("%d,", arr[i]);
    return 0;
}
void fun(int n, int arr[])
{
    int *p=0;
    int i=0;
    while(i++ < n)
        p = &arr[i];
    *p=0;
}





19.
What will be the output of the program if the array begins 1200 in memory?

#include<stdio.h>

int main()
{
    int arr[]={2, 3, 4, 1, 6};
    printf("%u, %u, %un", arr, &arr[0], &arr);
    return 0;
}





20.
What will be the output of the program ?

#include<stdio.h>
void fun(int **p);

int main()
{
    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};
    int *ptr;
    ptr = &a[0][0];
    fun(&ptr);
    return 0;
}
void fun(int **p)
{
    printf("%dn", **p);
}





21.
What will be the output of the program?

#include<stdio.h>
#define MAX(a, b) (a > b ? a : b)

int main()
{
    int x;
    x = MAX(3+2, 2+7);
    printf("%dn", x);
    return 0;
}



Explanation:

The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.

Step 1 : int x; The variable x is declared as an integer type.

Step 2 : x = MAX(3+2, 2+7); becomes,

=> x = (3+2 > 2+7 ? 3+2 : 2+7)

=> x = (5 > 9 ? 5 : 9)

=> x = 9

Step 3 : printf("%dn", x); It prints the value of variable x.

Hence the output of the program is 9.


22.
Which of the following statements are correct about 6 used in the program?
int num[6];
num[6]=21;





23.
What will be the output of the program?

#include<stdio.h>

int main()
{
    char huge *near *far *ptr1;
    char near *far *huge *ptr2;
    char far *huge *near *ptr3;
    printf("%d, %d, %dn", sizeof(ptr1), sizeof(*ptr2), sizeof(**ptr3));
    return 0;
}





24.
 
What will be the output of the program?

#include<stdio.h>
#define MESS junk

int main()
{
    printf("MESSn");
    return 0;
}



Explanation:

printf("MESSn"); It prints the text "MESS". There is no macro calling inside the printf statement occured.


25. In which header file is the NULL macro defined?



Explanation:

The macro "NULL" is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.


26.
  What will be the output of the program?

#include

int main()
{
    const c = -11;
    const int d = 34;
    printf("%d, %dn", c, d);
    return 0;
}



Explanation:

Step 1: const c = -11; The constant variable 'c' is declared and initialized to value "-11".

Step 2: const int d = 34; The constant variable 'd' is declared as an integer and initialized to value '34'.

Step 3: printf("%d, %dn", c, d); The value of the variable 'c' and 'd' are printed.

Hence the output of the program is -11, 34


27. The operator used to get value at address stored in a pointer variable is





28.
What do the following declaration signify?

int *ptr[30];





29.
What do the following declaration signify?

void (*cmp)();





30.
What will be the output of the program?

#include<stdio.h>

int main()
{
    const int i=0;
    printf("%dn", i++);
    return 0;
}



Explanation:

This program will show an error "Cannot modify a const object".

Step 1: const int i=0; The constant variable 'i' is declared as an integer and initialized with value of '0'(zero).

Step 2: printf("%dn", i++); Here the variable 'i' is increemented by 1(one). This will create an error "Cannot modify a const object".

Because, we cannot modify a const variable.




FreshersLive - No.1 Job site in India. Here you can find latest 2017 government as well as private job recruitment notifications for different posts vacancies in India. Get top company jobs for both fresher and experienced. Job Seekers can get useful interview tips, resume services & interview Question and answer. Practice online test free which is helpful for interview preparation. Register with us to get latest employment news/rojgar samachar notifications. Also get latest free govt and other sarkari naukri job alerts daily through E-mail.