ExamVeda
Login
Home
1
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    char *str = "hello, world\n";
    str[5] = '.';
    printf("%s\n", str);
    return 0;
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
2
Is the below declaration legal?
int* ((*x)())[2];
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
3
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int a[2][3] = {1, 2, 3, , 4, 5};
    int i = 0, j = 0;
    for (i = 0; i < 2; i++)
    for (j = 0; j < 3; j++)
    printf("%d", a[i][j]);
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
4
What will be the output of the following C code (run without any command line arguments)?
#include <stdio.h>
int main(int argc, char *argv[])
{
    while (*argv++ != NULL)
    printf("%s\n", *argv);
    return 0;
}
Discuss
Answer & Solution
Answer: Option A
Solution:
When the program is executed without any command line arguments, the argv array will contain only one element, which is the name of the executable file itself. In the while loop, *argv++ will first dereference argv, which points to the string containing the name of the executable file, and then increment argv to point to the next memory location, which would be NULL as there are no more command line arguments.
However, the loop does not check for the NULL pointer before dereferencing argv. Therefore, when argv is dereferenced after reaching the end of the argv array (i.e., when it points to NULL), it will cause a segmentation fault or code crash because it is attempting to access memory that is not valid.
Hence, the correct answer is Option A: Segmentation fault/code crash.
5
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char s[] = "hello";
    s++;
    printf("%c\n", *s);
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
6
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 11;
    int *p = &i;
    foo(&p);
    printf("%d ", *p);
}
void foo(int *const *p)
{
    int j = 10;
    *p = &j;
    printf("%d ", **p);
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
7
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int k = 5;
    int *p = &k;
    int **m  = &p;
    printf("%d%d%d\n", k, *p, **p);
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
8
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int x = 0;
    int *ptr = &5;
    printf("%p\n", ptr);
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
9
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    char *str = "hello, world\n";
    char *strc = "good morning\n";
    strcpy(strc, str);
    printf("%s\n", strc);
    return 0;
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
10
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char *s = "hello";
    char *p = s;
    printf("%c\t%c", *p, s[1]);
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board