Lesson1 Flashcards

1
Q

What is an array in C?

A

A collection of similar type of data items stored at contiguous memory locations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you declare an array in C?

A

data_type array_name[array_size];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the syntax for initializing an array during declaration?

A

data_type array_name[size] = {value1, value2, …, valueN};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the starting index for arrays in C?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What function is used to find the length of a string in C?

A

strlen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of pointers in C?

A

To store the address of another variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: An array can only store primitive data types.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Fill in the blank: An array is the simplest _______ structure in C.

A

data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the syntax for accessing an element in an array?

A

array_name[index];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the two types of arrays mentioned?

A
  • One-dimensional arrays
  • Two-dimensional arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you initialize an array using index?

A

By assigning values to each index individually, e.g., Arr[0]=value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a two-dimensional array?

A

An array of one-dimensional arrays, visualized as a table with rows and columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the output of accessing arr[1][0] in a 2D array defined as int arr[2][3] = { {1, 4, 2}, {3, 6, 8} };?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of the ‘sizeof’ operator in the context of arrays?

A

To determine the size of the array in bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the term ‘self-referential structure’ refer to?

A

A structure that contains a pointer to its own type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: You can use pointers to access elements of an array.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you read values into an array in C?

A

Using a loop and scanf to input each value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the output of the following code snippet? int marks[5] = {80, 60, 70, 85, 75}; printf(‘%d’, marks[2]);

A

70

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you find the sum of elements in an array?

A

Using a loop to iterate through the array and accumulate the sum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the formula to calculate the average of an array?

A

average = sum / number_of_elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the syntax for defining a structure in C?

A

struct structure_name { data_type member1; data_type member2; … };

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is an example of a basic string function in C?

A
  • strcat
  • strcpy
  • strstr
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Fill in the blank: A _______ can store multiple values in a single variable.

A

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does ‘union’ in C allow you to do?

A

Store different data types in the same memory location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the maximum number of dimensions an array can have in C?

A

Theoretically, it can be up to 255 dimensions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does the term ‘enumeration data type’ refer to?

A

A user-defined type consisting of a set of named integer constants

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How is memory allocated for an array in C?

A

The compiler allocates a block of memory based on the array’s size upon declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

True or False: Arrays in C can only hold integers.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the output of the following code snippet? printf(‘%d’, marks[5]); where marks is defined as int marks[5];

A

Undefined behavior (out of bounds access)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How do you sort an array in C?

A

Using a sorting algorithm like bubble sort, quicksort, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What are the two main operations performed on arrays?

A
  • Accessing elements
  • Modifying elements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is the significance of the index in an array?

A

It determines the position of an element within the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the syntax to declare a two-dimensional array?

A

data_type array_name[rows][columns];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is a string in C?

A

A one-dimensional array of characters terminated by a null character (‘\0’)

The null character is crucial for identifying the end of the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What differentiates a character array from a C string?

A

A C string is terminated with a unique character ‘\0’

This termination character allows the program to determine where the string ends.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is the syntax for declaring a C string?

A

char string_name[size];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

How is a string literal declared in C?

A

char ch2[11] = ‘javatpoint’;

The compiler automatically adds the ‘\0’ character.

38
Q

What does the strlen() function do?

A

Calculates the length of a given string excluding the null character.

39
Q

What is the purpose of the strcpy() function?

A

Copies the contents of the source string to the destination string.

40
Q

What does the strcat() function do?

A

Concatenates or joins the first string with the second string.

41
Q

What does the strcmp() function return?

A

Returns 0 if both strings are equal.

42
Q

What is the structure in C?

A

A user-defined data type that groups related variables of possibly different types into a single type.

43
Q

What keyword is used to define a structure in C?

A

struct

44
Q

What is the difference between an array and a structure?

A

An array is a homogeneous collection of similar types, while a structure can have elements of different types.

45
Q

What does the following code do? char arr[3][10] = {“Geek”, “Geeks”, “Geekfor”};

A

Defines an array of strings, where each string can hold up to 9 characters plus the null terminator.

46
Q

What is the output of the printf statement printing a string array?

A

Prints each string stored in the array, one per line.

47
Q

Fill in the blank: In C, an array of strings is a _______ array of character types.

A

two-dimensional

48
Q

What is the significance of the null character (‘\0’) in strings?

A

Indicates the termination of the string.

49
Q

How do you read a string input from the keyboard in C?

A

Using scanf(“%s”, str);

50
Q

What will the following code print? char str[] = “GeeksforGeeks”; length = strlen(str);

A

Length of the string, which is 13.

51
Q

True or False: The strcpy() function can copy one string to another of different sizes.

A

False

The destination must be large enough to hold the copied string.

52
Q

What is the output of the following code? printf(“%d\n”, strcmp(“Hello”, “Hello”));

A

0

53
Q

What is the purpose of the printf function in C?

A

To output formatted text to the console.

54
Q

What is the maximum number of string values that can be stored in a string array declared as char variable_name[r][m]?

A

r

55
Q

What is the maximum number of character values that can be stored in each string array declared as char variable_name[r][m]?

A

m

56
Q

What is the main difference between an array and a structure in C?

A

An array is a homogenous collection of similar types, while a structure can have elements of different types.

57
Q

How do you declare a structure in C?

A

Using the struct keyword followed by the structure name and member variables with their data types.

58
Q

What is the syntax for declaring a structure in C?

A

struct structure_name { data_type member_name1; data_type member_name2; … };

59
Q

What is a structure template in C?

A

The syntax used to declare a structure without allocating memory.

60
Q

Provide an example of a structure declaration for a Book.

A

struct book { char title[50]; char author[50]; double price; int pages; };

61
Q

How do you create an instance of a structure in C?

A

By defining variables of the structure type.

62
Q

What are the two methods to define structure variables?

A
  • Structure Variable Declaration with Structure * Structure Variable Declaration after Structure definition
63
Q

How do you access members of a structure?

A

Using the dot operator (.) or the structure pointer operator (->).

64
Q

What is the output of printf when accessing structure members?

A

It displays the values of the structure’s members.

65
Q

What is an array of structures in C?

A

A collection of multiple structure variables where each variable contains information about different entities.

66
Q

How do you define an array of structures?

A

struct book b[3] = { {“Learn C”, 650.50, 325}, {“C Pointers”, 175, 225}, {“C Pearls”, 250, 250} };

67
Q

What is a union in C?

A

A user-defined data type that can contain elements of different data types, but only one member can store data at a time.

68
Q

What is the main advantage of using unions?

A

Unions provide an efficient way of using the same memory location for multiple purposes.

69
Q

What is the syntax for defining a union?

A

union union_name { datatype member1; datatype member2; … };

70
Q

How do you initialize a union member?

A

By assigning a value to the member directly after declaring a union variable.

71
Q

What is a pointer in C?

A

A derived data type that can store the address of other C variables or a memory location.

72
Q

What is the syntax for declaring a pointer?

A

datatype *ptr;

73
Q

How do you assign an address to a pointer?

A

ptr = &var; where var is a variable.

74
Q

What operator is used to dereference a pointer?

A

The asterisk (*) operator.

75
Q

What happens when you change the value of a pointer’s location?

A

It updates the value of the variable that the pointer is pointing to.

76
Q

What is the output of a program that prints the size of a structure?

A

It displays the total size in bytes of the structure.

77
Q

Fill in the blank: An array of structures in C can be defined as the collection of multiple _______.

A

structure variables

78
Q

What is the data type of the variable ‘x’ in the code?

A

int

79
Q

What is the data type of the variable ‘y’ in the code?

A

float

80
Q

What is the data type of the variable ‘z’ in the code?

A

char

81
Q

How is the pointer ‘ptr_x’ initialized?

A

ptr_x = &x

82
Q

What type of pointer is ‘ptr_y’?

A

float *

83
Q

What does ‘ptr_z’ point to?

A

char

84
Q

What is the output format specifier for an integer in printf?

A

%d

85
Q

What is the output format specifier for a float in printf?

A

%f

86
Q

What is the output format specifier for a char in printf?

A

%c

87
Q

What is the output of ‘printf(“Value of x = %d\n”, *ptr_x);’

A

Value of x = 10

88
Q

What is the output of ‘printf(“Value of y = %f\n”, *ptr_y);’

A

Value of y = 1.300000

89
Q

What is the output of ‘printf(“Value of z = %c\n”, *ptr_z);’

A

Value of z = p

90
Q

Fill in the blank: The pointer ‘ptr_x’ is of type _______.

A

int *

91
Q

True or False: The value of ‘y’ is printed as 1.3.

A

False

92
Q

What does the ‘*’ operator do when used with a pointer?

A

Dereferences the pointer