Computer Knowledge
Programming, networking, database and OS questions
65 Questions 5 Topics Take Test
Advertisement
Showing 41–50 of 65 questions
Q.41 Hard C Programming
What is the difference between declaration and definition in C?
A They are the same thing
B Declaration informs compiler about type, definition allocates memory
C Definition comes before declaration
D Declaration is only for functions
Correct Answer:  B. Declaration informs compiler about type, definition allocates memory
EXPLANATION

Declaration tells the compiler about a variable's name and type (e.g., 'extern int x;'). Definition actually allocates memory (e.g., 'int x = 5;'). A variable can be declared multiple times but defined only once.

Take Test
Q.42 Hard C Programming
Consider: int arr[10]; int *p = arr; What is p[5] equivalent to?
A &arr[5]
B *arr + 5
C *(arr + 5) or arr[5]
D Cannot be determined
Correct Answer:  C. *(arr + 5) or arr[5]
EXPLANATION

Array name decays to pointer. p[5] is equivalent to *(p+5) which is *(arr+5) or arr[5]. This demonstrates pointer arithmetic.

Take Test
Q.43 Hard C Programming
What does the static keyword do when used with a global variable?
A Makes it accessible only within the same file
B Makes it a constant
C Increases its memory allocation
D Makes it thread-safe
Correct Answer:  A. Makes it accessible only within the same file
EXPLANATION

When static is used with a global variable, it restricts its scope to the file where it is declared. Without static, global variables are accessible across files using extern.

Take Test
Q.44 Hard C Programming
What will be the output of: int a = 5; int *p = &a; printf("%d %d", a, *p);?
A 5 garbage value
B 5 5
C address address
D 0 5
Correct Answer:  B. 5 5
EXPLANATION

p is a pointer storing the address of a. *p (dereferencing) gives the value at that address, which is 5. So both a and *p print 5.

Take Test
Q.45 Hard C Programming
In C, when passing arrays to functions, what is actually passed?
A A copy of all array elements
B The address of the first element (pointer)
C The array size
D All array elements and size
Correct Answer:  B. The address of the first element (pointer)
EXPLANATION

When an array is passed to a function in C, it decays to a pointer pointing to the first element. This is why changes made in the function affect the original array.

Take Test
Q.46 Hard C Programming
In C, what is the purpose of the typedef keyword?
A Define a new data type
B Create an alias for existing data types
C Declare type of variables
D Convert one data type to another
Correct Answer:  B. Create an alias for existing data types
EXPLANATION

typedef creates an alias (synonym) for existing data types. For example, 'typedef int Integer;' creates 'Integer' as an alias for 'int'. This improves code readability and portability. It doesn't create entirely new types, but provides alternative names.

Take Test
Q.47 Hard C Programming
Which of the following function declarations is correct for a function that takes no parameters and returns no value?
A void function(void);
B void function();
C null function(void);
D void function(null);
Correct Answer:  A. void function(void);
EXPLANATION

The correct syntax is 'void function(void);' where 'void' in parentheses explicitly states no parameters. Option B is also valid in C (defaults to no parameters), but option A is more explicit and portable across C standards.

Take Test
Q.48 Hard C Programming
What is the difference between structure and union in C?
A Both allocate memory to all members simultaneously
B Structure allocates memory to all members; union allocates shared memory
C Union allocates memory to all members; structure allocates shared memory
D No difference
Correct Answer:  B. Structure allocates memory to all members; union allocates shared memory
EXPLANATION

Structure allocates separate memory for each member (total size = sum of all members). Union shares a single memory location among all members (total size = size of largest member). This is a fundamental difference in memory allocation.

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

x++ is post-increment (returns 5, then x becomes 6), ++x is pre-increment (x becomes 7, then returns 7). The order of evaluation in printf is implementation-dependent, but typically right to left, giving 5 7.

Take Test
Q.50 Hard C Programming
Which of the following is an invalid identifier in C?
A myVar
B my_var
C my$var
D _myVar
Correct Answer:  C. my$var
EXPLANATION

In C, identifiers can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores (_), and must start with a letter or underscore. The dollar sign (\() is not allowed, making 'my\)var' invalid.

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