AmbitionBox

Discover Best Places to work in India

C Programming

C Programming Questions and Answers

Showing 91 - 100 of 103 questions

91

What will be the output of the program if the array begins at address 65486?

#include < stdio.h >int main()
{
    int arr[] = {12, 14, 15, 23, 45};
    printf("%u, %u\n", arr, &arr);
    return0;
}
a

65486, 65488

b

65486, 65486

c

65486, 65490

d

65486, 65487

correct answer b
Answer :

Option B

Explanation :

Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized.
Step 2: printf("%u, %u\n", arr, &arr); Here,
The base address of the array is 65486.
=> arr, &arr is pointing to the base address of the array arr.

Hence the output of the program is 65486, 65486

92

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, %u\n", arr, &arr[0], &arr);
    return0;
}
a

1200, 1202, 1204

b

1200, 1200, 1200

c

1200, 1204, 1208

d

1200, 1202, 1200

correct answer b
Answer :

Option B

Explanation :

Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array and initialized.
Step 2: printf("%u, %u, %u\n", arr, &arr[0], &arr); Here,
The base address of the array is 1200.
=> arr, &arr is pointing to the base address of the array arr.
=> &arr[0] is pointing to the address of the first element array arr. (ie. base address)

Hence the output of the program is 1200, 1200, 1200

93

Which of the following is correct way to define the function fun() in the below program?

#includeint main()
{
    int a[3][4];
    fun(a);
    return0;
}
a

void fun(int p[][4])
{
}

b

void fun(int *p[4])
{
}

c

void fun(int *p[][4])
{
}

d

void fun(int *p[3][4])
{
}

correct answer a
Answer :

Option A

Explanation :

void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are considered only the function fun() is called by using call by reference.

94

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.

a

1

b

1,4

c

2,3

d

2,4

correct answer b
Answer :

Option B

Explanation :

1. The array int num[26]; can store 26 elements. This statement is true.
2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.
3. It is necessary to initialize the array at the time of declaration. This statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.

Hence the statements '1' and '4' are correct statements.

95

Point out the error in the program?

#include < stdio.h >#include < stdlib.h >int main()
{
    unsignedchar;
    FILE *fp;
    fp=fopen("trial", "r");
    if(!fp)
    {
        printf("Unable to open file");
        exit(1);
    }
    fclose(fp);
    return0;
}
a

Error: in unsigned char statement

b

Error: unknown file pointer

c

No error

d

None of above

correct answer c
Answer :

Option C

Explanation :

This program tries to open the file trial.txt in read mode. If file not exists or unable to read it prints "Unable to open file" and then terminate the program.
If file exists, it simply close the file and then terminates the program.

96

Point out the error in the program?

#include < stdio.h >/* Assume there is a file called 'file.c' in c:\tc directory. */int main()
{
    FILE *fp;
    fp=fopen("c:\tc\file.c", "r");    
    if(!fp) 
      printf("Unable to open file.");        

    fclose(fp);
    return0;
}
a

No error, No output.

b

Program crashes at run time.

c

Output: Unable to open file.

d

None of above

correct answer c
Answer :

Option C

Explanation :

The path of file name must be given as "c:\\tc\file.c"

97

Point out the error/warning in the program?

#include < stdio.h >int main()
{
    unsignedchar ch;
    FILE *fp;
    fp=fopen("trial", "r");
    while((ch = getc(fp))!=EOF)
        printf("%c", ch);
    fclose(fp);
    return0;
}
a

Error: in unsigned char declaration

b

Error: while statement

c

No error

d

It prints all characters in file "trial"

correct answer a
Answer :

Option A

Explanation :

Here, EOF is -1. As 'ch' is declared as unsigned char it cannot deal with any negative value.

98

Point out the correct statements about the program?

#includeint main()
{
    FILE *fptr;
    char str[80];
    fptr = fopen("f1.dat", "w");
    if(fptr == NULL)
        printf("Cannot open file");
    else
    {
        while(strlen(gets(str))>0)
        {
            fputs(str, fptr);
            fputs("\n", fptr);
        }
        fclose(fptr);
    }
    return0;
}
a

The code copies the content of one file to another

b

The code writes strings that are read from the keyboard into a file.

c

The code reads a file

d

None of above

correct answer b
Answer :

Option B

Explanation :

This program get the input string from the user through gets function and store it in the file f1.txt using fputs function.

99

What is x in the following program?

#include < stdio . h >int main()
{
    typedefchar (*(*arrfptr[3])())[10];
    arrfptr x;
    return0;
}
a

x is a pointer

b

x is an array of three pointer

c

x is an array of three function pointers

d

Error in x declaration

correct answer c
Answer :

Option C

100

What will be the output of the program?

#includetypedefstruct error {int warning, err, exception;} ERROR;
int main()
{
    ERROR e;
    e.err=1;
    printf("%d\n", e.err);
    return0;
}
a

0

b

1

c

2

d

Error

correct answer b
Answer :

Option B

Select a company to compare with

vs

Similar Companies