Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

150 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 111–120 of 150
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.111 Medium C Programming
What is the output of: int a = 10, b = 20; int temp = a; a = b; b = temp; printf("%d %d", a, b);?
A 10 20
B 20 10
C 20 20
D 10 10
Correct Answer:  B. 20 10
EXPLANATION

This is a swap operation. Initially a=10, b=20. After temp=a (temp=10), a=b (a=20), b=temp (b=10). Output: 20 10.

Take Test
Q.112 Medium C Programming
Which function is used to allocate memory dynamically in C?
A allocate()
B malloc()
C new()
D create()
Correct Answer:  B. malloc()
EXPLANATION

malloc() (memory allocation) is used to dynamically allocate memory on the heap in C. It requires #include <stdlib.h>. new() is used in C++, not C.

Take Test
Q.113 Medium C Programming
What will be the output of: int x = 5; int y = ++x; printf("%d %d", x, y);?
A 5 5
B 6 6
C 5 6
D 6 5
Correct Answer:  B. 6 6
EXPLANATION

The pre-increment operator (++x) increments x first, then assigns it. So x becomes 6, and y is assigned 6. Output: 6 6.

Take Test
Q.114 Medium C Programming
Which loop in C does NOT check the condition before executing the loop body?
A for loop
B while loop
C do-while loop
D foreach loop
Correct Answer:  C. do-while loop
EXPLANATION

The do-while loop executes the loop body at least once before checking the condition. Other loops check the condition before execution. Syntax: do { } while(condition);

Take Test
Q.115 Medium C Programming
What will be the output of: int x = 5; x += 3; printf("%d", x);?
A 5
B 8
C 3
D 53
Correct Answer:  B. 8
EXPLANATION

The operator += means x = x + 3. So x = 5 + 3 = 8. The printf statement outputs 8.

Take Test
Q.116 Medium C Programming
What is the output of the following: int x = 5; int *p = &x; printf("%d", *p);?
A Address of x
B 5
C Garbage value
D Error
Correct Answer:  B. 5
EXPLANATION

p is a pointer to x, so &x gives the address of x. *p (dereferencing) gives the value stored at that address, which is 5. The output will be 5.

Take Test
Q.117 Medium C Programming
Which function is used to compare two strings in C?
A strcmp()
B strcomp()
C compare()
D strcmpare()
Correct Answer:  A. strcmp()
EXPLANATION

strcmp() is the standard library function used to compare two strings. It returns 0 if strings are equal, negative if first string is less, and positive if first string is greater. It's declared in string.h.

Take Test
Q.118 Medium C Programming
What will be the output of: char str[] = "Hello"; printf("%c", str[1]);?
A H
B e
C l
D o
Correct Answer:  B. e
EXPLANATION

Array indexing in C starts from 0. str[0]='H', str[1]='e', str[2]='l', str[3]='l', str[4]='o', str[5]='\0'. Therefore, str[1] is 'e'.

Take Test
Q.119 Medium C Programming
Which of the following is used to dynamically allocate memory in C?
A new()
B alloc()
C malloc()
D create()
Correct Answer:  C. malloc()
EXPLANATION

malloc() (memory allocation) is the standard function in C for dynamic memory allocation. It returns a void pointer to the allocated memory. The syntax is: ptr = (type*)malloc(size);

Take Test
Q.120 Medium C Programming
What will be printed if char ch = 'A'; printf("%d", ch); is executed?
A A
B 65
C 97
D 41
Correct Answer:  B. 65
EXPLANATION

When %d format specifier is used with a char variable, it prints the ASCII value. The ASCII value of 'A' is 65. If it were 'a', the value would be 97.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips