My Report

C Programming Practice Test 10


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. The following C code is an example of __________

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
    char *p,*q;
    p=(char*)malloc(3*sizeof(char));
    q=p;
    strcpy(p,"hello");
    printf("p=%s",p);
    printf("q=%s",q);
    free(q);
    q=NULL;
    gets(p);
    gets(q);
    printf("%s",p);
    printf(ā€œ%sā€,q);
}

2. What will be the output of the following C code?

#include<stdio.h>
#define sf 10
main()
{
    if(sf==100)
        printf("good");
    else
    {
        printf("bad");
        sf=100;
    }
    printf("%d",sf);
}

3. The pragma ___________________ is used to remove an identifier completely from a program.

4. _____________ defines the minimum value for a short integer.

5. What will be the output of the following C code?

#include <stdio.h>
#define hello( n ) a##n
int a3;
int main()
{
    int x;
    x=hello(3);
    if(x!=0)
        printf("hi");
    else
        printf("good");
}

6. What will be the output of the following C code if the input entered as first and second number is 5 and 6 respectively?

#include<stdio.h>
#include<stdlib.h>
main()
{
    int *p;
    p=(int*)calloc(3*sizeof(int));
    printf("Enter first number\n");
    scanf("%d",p);
    printf("Enter second number\n");
    scanf("%d",p+2);
    printf("%d%d",*p,*(p+2));
    free(p);
}

7. The preprocessor directive which is used to remove the definition of an identifier which was previously defined with #define?

8. Which of the following functions allocates multiple blocks of memory, each block of the same size?

9. The macro MB_LEN_MAX is used to find _________

10. Given that the value of SHRT_MAX is equal to 32767 and that of SHRT_MIN is equal to -32768, What will be the output of the following C code?

#include<stdio.h>
#include<limits.h>
main()
{
    int d;
    d=SHRT_MAX + SHRT_MIN+1;
    printf("%d",d);
}

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.