Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Infosys C Language Questions

Last Updated on February 22, 2023 by Prepbytes

Infosys is an Indian multinational technology company that offers consulting, technology, and outsourcing services to clients worldwide. Founded in 1981, Infosys has grown to become one of the largest IT services firms in the world.

The company’s services include digital transformation, application development, data analytics, cloud computing, and cybersecurity. Infosys has also developed proprietary software products for various industries, such as Finacle for banking and Edge for the supply chain management.

Infosys Recruitment Process

Infosys recruitment process typically involves several stages:

  • Online Test
  • Technical Round
  • HR Round

Online Test

The Infosys online test contains questions on quantitative ability, reasoning ability, and verbal ability. The test lasts 95 minutes. Each section of the test, such as Quantitative Ability, Reasoning Ability, and Verbal Ability, has a specific time allotted to it, and all questions in that area must be completed within that time span. The candidate can attempt questions in any sequence in a specific area but cannot move across parts, which means the candidate must first complete one section before moving on to the others.

Technical Round

Candidates who passed the online test proceed to the technical round. This round evaluates your concepts together with your technical skill. The topics covered by the questions will be diverse. Data structures and algorithms, DBMS, operating systems, networking, OOPs concepts, and a programming language of choice should all be prepared. Students from fields other than computer science should study the fundamental concepts of their field. Some hard questions may be asked.

HR Round

This is the final step in the hiring process. Questions about your resume, job, and company may be asked, along with standard HR questions like ‘What are your Career Goals?’, ‘Why Infosys?’ and so on. They will evaluate your communication skills, confidence, and attitude. If you think clearly and confidently, you will easily pass this round.

Infosys C Language Questions: Fundamentals

In this section, we will look at several basic Infosys C Language Questions

Q – 1 Why is C called a mid-level programming language?
Answer – C is considered a mid-level programming language because it provides a level of abstraction that is higher than low-level assembly languages but lower than high-level languages like Python or Java.

C is closer to the hardware and provides low-level access to system resources such as memory, I/O operations, and other hardware components, making it suitable for systems programming, embedded systems, and operating system development.

However, C also has higher-level constructs like functions, structures, and pointers, which make it easier to write complex programs and manage data structures. This combination of low-level and high-level features makes C a mid-level programming language.

Q – 2 What is a structure in C language?
Answer – A structure in C language is a user-defined data type that groups together variables of different data types under a single name. It allows the programmer to create a composite data type that can represent a complex entity, such as a record, a point in space, or a person’s information.

The syntax for structure in C is :

struct structure_name {
   data_type1 variable1;
   data_type2 variable2;
   // ... more
};

Here, structure_name is the name of the structure, and variable1, variable2, etc. are the members of the structure, each with their own data type.

To declare a variable of the structure type, the following syntax is used:

struct structure_name variable_name;

After defining the structure, the members can be accessed using the dot (.) operator as follows:

variable_name.variable1 = value1;
variable_name.variable2 = value2;
// ... more other members

Structures in C are commonly used for creating data structures, passing complex parameters to functions, and representing records in a file or a database. They are an important feature of the language and are used extensively in system programming, network programming, and game development.

Q – 3 What is the difference between a structure and a union in C language?
Answer – In C language, a structure is a composite data type that groups together variables of different data types under a single name, while a union is a special data type that allows the same memory location to be used for different variable types at different times.

In a structure, each member has its own memory location, and the total size of the structure is the sum of the sizes of its members. In contrast, a union uses the same memory location for all of its members, and the size of the union is the size of its largest member.

Structures are typically used when you need to group related data together, while unions are typically used when you need to represent the same data in different ways or when you want to save memory by reusing the same memory location for different purposes.

Q – 4 What is dynamic memory allocation in C programming language?
Answer – Dynamic memory allocation in C programming language is the process of allocating and deallocating memory for variables during program execution. In contrast to static memory allocation, where memory is allocated at compile-time and the size is fixed throughout the program, dynamic memory allocation allows the program to request memory from the operating system during runtime and free it when it is no longer needed.

In C, dynamic memory allocation is typically performed using the functions malloc(), calloc(), and realloc(). malloc() allocates a block of memory of a specified size and returns a pointer to the first byte of the block. calloc() allocates a block of memory and initializes it to zero. realloc() is used to resize a previously allocated block of memory.

Once memory has been dynamically allocated, it can be accessed using pointers. It is important to manage dynamic memory carefully to avoid memory leaks, where memory is allocated but never freed, or invalid memory accesses, where memory is accessed after it has been freed. Memory leaks and invalid memory accesses can cause program crashes or other unexpected behavior.

Q – 5 What are the storage classes in the C programming language?
Answer – The C programming language provides four storage classes for variables and functions, which control the lifetime, scope, and visibility of the identifiers in the program:

  • auto: The auto storage class is the default storage class for local variables, which are declared inside a function or block. The variables are allocated on the stack and are automatically initialized to garbage values.
  • register: The register storage class is used to suggest the compiler to store the variable in a CPU register instead of memory. This can lead to faster access times for frequently used variables.
  • static: The static storage class is used to declare variables with a lifetime that extends throughout the program’s execution. These variables are allocated in the data segment and are initialized to zero by default. Static variables can be either global or local to a function.
  • extern: The extern storage class is used to declare variables or functions that are defined in another file or module. This enables the variables or functions to be shared across different files and modules in a program.

Q – 6 What are static variables in C programming language?
Answer – In C programming language, a static variable is a type of variable that has a lifetime that extends throughout the program’s execution, rather than just within a particular function or block. Static variables are declared using the static keyword, either within a function or outside of any function, and are allocated in the data segment of the program’s memory.

Static variables are initialized to zero by default, and they retain their values between function calls. This makes them useful for maintaining state across function calls, or for storing values that should not be reinitialized each time a function is called.

Static variables declared within a function are only visible within that function, and are not accessible from outside the function. However, static variables declared outside of any function are visible to all functions in the same file, and can be accessed from any function within that file.

One important thing to keep in mind when using static variables is that they are not thread-safe. If multiple threads access the same static variable simultaneously, it can lead to race conditions and other synchronization issues. Therefore, static variables should be used with caution in multithreaded programs.

Q – 7 Why doesn’t C support function overloading?
Answer – C programming language does not support function overloading, which is the ability to define multiple functions with the same name but different parameter lists, because C uses a simple name mangling scheme based on the function name only.

In C, the function name is not decorated with additional information about the function’s parameter types or return type. Therefore, the compiler cannot distinguish between different overloaded functions based on their parameter types, which can lead to ambiguity and confusion.

Instead, in C, functions that perform similar operations but have different input or output types are typically given different names, or the function names are made more specific to differentiate them. This can lead to longer and more descriptive function names, but it helps to avoid confusion and ambiguity.

However, it is worth noting that some C libraries or frameworks implement similar functionality to function overloading by defining different functions with different names but the same functionality.

Q – 8 What are Enumerations?
Answer – Enumerations, also known as enums, are user-defined data type in C programming language that enable developers to define a set of named values, where each value represents a distinct constant. Enums are typically used to improve code readability and maintainability by providing a descriptive name for each value.

An enumeration is declared using the enum keyword, followed by a list of named values, separated by commas and enclosed in curly braces. For example,

enum color {
   RED,
   GREEN,
   BLUE
};

In this example, we have defined an enumeration named color with three named values: RED, GREEN, and BLUE. The names are case-sensitive and must be unique within the enumeration.

Enums can be used to define variables with the enum type, as well as function parameters and return types. For example,

enum color c = RED;
void setColor(enum color c) {...}
enum color getColor() {...}

Enums are implemented as integer constants by default, where the first value is assigned the integer value 0, the second value is assigned the integer value 1, and so on. However, you can also explicitly assign integer values to individual names in the enumeration. For example

enum color {
   RED = 1,
   GREEN = 2,
   BLUE = 4
};

In this example, RED has the integer value 1, GREEN has the integer value 2, and BLUE has the integer value 4. The remaining values are assigned the next integer values in sequence, starting from the previous value plus one.

Q – 9 What is the difference between malloc() and calloc()?
Answer – Both malloc() and calloc() are used for dynamic memory allocation in the C programming language. However, they differ in how they allocate and initialize the memory.

malloc() is used to allocate a block of memory of a specified size, in bytes. It returns a pointer to the beginning of the block of memory, which can be used to store data. The malloc() function does not initialize the memory it allocates, so the memory may contain garbage values. It is up to the programmer to initialize the memory before using it.

calloc() is also used to allocate a block of memory of a specified size, in bytes. However, it differs from malloc() in that it initializes the memory to zero. This can be useful when you need to allocate an array of elements and you want to make sure that all elements are initially set to zero.

The calloc() function takes two arguments: the number of elements to allocate, and the size of each element in bytes. It returns a pointer to the beginning of the block of memory, which can be used to store data.

In summary, the main difference between malloc() and calloc() is that malloc() only allocates memory, while calloc() allocates and initializes memory to zero. calloc() is often used for allocating arrays of elements, while malloc() is used for allocating single blocks of memory.

Q – 10 What is the use of printf() and scanf() functions?
Answer – printf() and scanf() are two of the most commonly used input/output functions in the C programming language.

printf() is used to print output to the console or terminal. It allows you to format and print data, such as numbers, characters, and strings. The printf() function takes one or more arguments, which specify the data to be printed and how to format it.

For example, you can use the printf() function to print a message to the console, like this:

printf("Hello, world!\n");

The \n character is used to add a newline after the message.

scanf() is used to read input from the console or terminal. It allows you to read data, such as numbers, characters, and strings, from the user. The scanf() function takes one or more arguments, which specify the type of data to be read and where to store it.

For example, you can use the scanf() function to read an integer value from the user, like this:

int n;
printf("Enter an integer: ");
scanf("%d", &n);

The %d format specifier is used to read an integer value, and the & operator is used to pass the address of the variable n to scanf() so that the input value can be stored in n.

In summary, printf() is used to print output to the console or terminal, while scanf() is used to read input from the console or terminal. Both functions are essential for interacting with users in console-based C programs.

Infosys C Language Questions: Coding

In this section, we will discuss Infosys C Language: Coding Questions.

Q – 1 Write a C program to check if it is a palindrome number or not using a recursive method.
Ans –

#include <stdio.h>

int isPalindrome(int num, int temp) {
   if (num == 0) {
      return temp;
   }
   temp = (temp * 10) + (num % 10);
   return isPalindrome(num / 10, temp);
}

int main() {
   int num, temp;
   scanf("%d", &num);
   temp = isPalindrome(num, 0);
   if (temp == num) {
      printf("%d is a palindrome number.", num);
   } else {
      printf("%d is not a palindrome number.", num);
   }
   return 0;
}

Input

1221

Output

1221 is a palindrome number.

Q – 2 Write a C program to Add Two Numbers Without Using the Addition Operator
Ans –

#include <stdio.h>

int addWithoutPlus(int num1, int num2) {
   int carry;
   while (num2 != 0) {
      carry = num1 & num2;
      num1 = num1 ^ num2;
      num2 = carry << 1;
   }
   return num1;
}

int main() {
   int num1, num2, sum;
   scanf("%d", &num1);
   scanf("%d", &num2);
   sum = addWithoutPlus(num1, num2);
   printf("The sum of %d and %d is %d\n", num1, num2, sum);
   return 0;
}

Input

12 17

Output

The sum of 12 and 17 is 29

Q – 3 Write a C program to check the given number format is in binary or not.
Ans –

#include <stdio.h>
#include <stdbool.h>

bool isBinary(int num) {
   while (num != 0) {
      int digit = num % 10;
      if (digit != 0 && digit != 1) {
         return false;
      }
      num /= 10;
   }
   return true;
}

int main() {
   int num;
   scanf("%d", &num);
   if (isBinary(num)) {
      printf("%d is in binary format.\n", num);
   } else {
      printf("%d is not in binary format.\n", num);
   }
   return 0;
}

Input

101

Output

101 is in binary format.

Q – 4 Write a C program to Subtract Two Numbers Without Using the Subtraction Operator
Ans –

#include <stdio.h>

int subtractWithoutMinus(int num1, int num2) {
   while (num2 != 0) {
      int borrow = (~num1) & num2;
      num1 = num1 ^ num2;
      num2 = borrow << 1;
   }
   return num1;
}

int main() {
   int num1, num2, difference;
   scanf("%d", &num1);
   scanf("%d", &num2);
   difference = subtractWithoutMinus(num1, num2);
   printf("The difference between %d and %d is %d\n", num1, num2, difference);
   return 0;
}

Input

15 7

Output

The difference between 15 and 7 is 8

Q – 5 Write a C program to remove duplicates in a given array?
Ans –

#include <stdio.h>

int removeDuplicates(int arr[], int n) {
   int count = 0;
   for (int i = 0; i < n; i++) {
      int j;
      for (j = 0; j < i; j++) {
         if (arr[i] == arr[j]) {
            break;
         }
      }
      if (j == i) {
         arr[count++] = arr[i];
      }
   }
   return count;
}

int main() {
   int n;
   scanf("%d", &n);
   int arr[n];
   for (int i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
   }
   n = removeDuplicates(arr, n);
   printf("The array after removing duplicates is: ");
   for (int i = 0; i < n; i++) {
      printf("%d ", arr[i]);
   }
   printf("\n");
   return 0;
}

Input

8
1 4 6 4 1 5 6 9

Output

The array after removing duplicates is: 1 4 6 5 9

Frequently Asked Questions (FAQs)

Below are some FAQs on Infosys C language Questions

Q1: What is the difficulty level of Infosys C language questions?
A: The difficulty level of Infosys C language questions can vary depending on the job position and the level of the candidate’s experience. Typically, Infosys C language questions for entry-level positions are of moderate difficulty and focus on fundamental concepts, while the questions for experienced positions may be more complex and cover advanced topics.

Q2: How to prepare for Infosys C language questions?
A: To prepare for Infosys C language questions, candidates should focus on mastering the basic concepts of the language and practice coding exercises and sample questions. They can refer to standard textbooks and online resources that cover C programming in detail. Candidates can also take mock tests and practice previous year’s question papers to get a sense of the type of questions asked and the level of difficulty. Additionally, they can participate in coding challenges and competitions to enhance their skills and gain practical experience.

Q3: Are Infosys C language questions only asked in written tests, or are they also asked in interviews?
A: Infosys C language questions are typically asked in both written tests and interviews. In written tests, candidates may be asked multiple-choice or descriptive questions to test their understanding of the language’s syntax, data types, and programming constructs. In interviews, the questions may be more focused on the candidate’s problem-solving ability, coding skills, and ability to design and implement programs using C. The interviewer may also ask the candidate to explain their code, provide alternate solutions, and discuss the trade-offs and limitations of different approaches.

Leave a Reply

Your email address will not be published. Required fields are marked *