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!

Accenture C language Questions

Last Updated on July 3, 2023 by Mayank Dham

Accenture is a multinational company renowned for its proficiency in delivering outsourcing, business, information technology, and consultancy services. Due to its global reputation and several other factors such as a positive work environment, competitive salary benefits, international exposure, and opportunities for growth, Accenture stands as a top choice for candidates seeking employment. These combined aspects give Accenture a competitive advantage over many other companies operating in the same industry, making it an appealing option for prospective candidates looking to secure their future career prospects.

To get into Accenture you have to go through a proper hiring process and in that, you will be asked various questions on various domains like aptitude, operating systems, computer networks, and programming, The programming questions will be of the selected programming language. Here we have compiled a list of the commonly asked questions in Accenture interviews.

Accenture C Language Questions

Now, we will look at the previously asked C language questions in Accenture interviews.

1. Mention some of the features of C language?
Ans: Here are some of the features of the C programming language:

  • Procedural programming: C is a procedural programming language, which means it follows a step-by-step approach to solving problems.
  • Portability: C code can be compiled on different platforms and architectures, making it a portable language.
  • Structured programming: C supports structured programming, which allows you to break down your code into smaller, more manageable functions.
  • Low-level programming: C allows you to write low-level code that can interact with hardware and memory directly, making it ideal for system programming.
  • Strongly-typed: C is a strongly-typed language, which means it requires variables to be declared before they can be used, and it enforces strict type-checking.

2. Explain call by a reference and call by value in C.
Ans: In C, there are two ways to pass arguments to a function: call by reference and call by value.

Call by value means that a copy of the argument is passed to the function. The function cannot modify the original variable, as it only has access to the copy of the variable passed as an argument. The original variable remains unchanged.

Call by reference means that the function receives a reference (i.e., the memory address) to the original variable. This allows the function to modify the original variable, as it has direct access to it in memory. To pass an argument by reference, you need to use a pointer as the parameter.

3. Explain types of recursion in C programming language?
Ans: There are mainly six types of recursion.

  • Linear recursion: is a recursive function that calls itself only once and reduces the problem size by a constant amount at each step.
  • Tail recursion: is a type of recursion where the function calls itself as the last operation before returning. This is considered more efficient than regular recursion as it can be optimized by the compiler into a loop.
  • Binary recursion: is a type of recursion where a function calls two instances of itself to solve a problem and reduces the problem size by half at each step.
  • Exponential recursion: is a type of recursion where the problem size is reduced by a constant factor of less than one at each step.
  • Nested recursion: is a type of recursion where a function calls another function that calls the original function, and the problem size is reduced at each step by a constant amount.
  • Mutual recursion: is a type of recursion where two or more functions call each other cyclically to solve a problem. This method is used for problems that can be divided into two or more parts, each solvable by a different function.

4. What are macros in C programming language?
Ans: In C programming language, macros are a feature that allows developers to define a set of instructions or expressions that can be replaced by the preprocessor before the compilation process. A macro is defined using the #define directive, which specifies a name for the macro and the corresponding sequence of instructions or expressions that should be substituted in the code.
Macros are often used to define constants, to simplify complex expressions, or to create more readable code. However, it is important to use macros with caution, as they can be difficult to debug and may lead to unexpected behavior if not used properly.

5. What do you understand by enumeration?
Ans: A named group of associated values that each represent different components of a data type is referred to as an enumeration in programming. An enumeration is, in other words, a collection of named constants that each stand for a particular value.

In programming languages, enumerations are often declared using a particular syntax, such as the enum keyword in C, C++, and Java, or the Enum keyword in Python. Each enumerated item has a name and a value that may be utilized in the code in place of literal values.
Enumerations provide the principal benefit of improving the readability and maintainability of the code. For instance, an enumeration may be used to give these values meaningful names rather than representing them with magic numbers or string literals. When the code’s objective is made obvious, this can make the code simpler to comprehend and less likely to include errors.

6. What do you understand by the term scope of a variable?
Ans: A variable’s scope is the area of a program where it is declared and from which it may be accessed or utilized. In other words, it establishes a variable’s accessibility and visibility within a program.

Global scope and local scope are the two primary categories of scope. Anywhere in the program can access a variable that has been defined outside of all functions since it has a global scope. A variable declared inside a function, on the other hand, has a local scope and is only used inside that function.
The scope of a variable impact how it may be used and modified inside a program, therefore understanding it is crucial. The local scope will take priority over and shadow the global scope, for instance, if a variable with the same name is defined in both a global scope and a local scope. Inside the local scope, it will not be possible to access or modify the value of the variable with a global scope.

7. What do you understand by the null and void pointers in C language?
Ans: In C language, a null pointer is a pointer that points to no memory location, i.e., it has a value of zero. A null pointer can be created by assigning the literal value NULL to a pointer variable or by initializing a pointer variable without assigning any value to it. A null pointer is often used as a sentinel value to indicate the end of a list or to indicate that a pointer variable is not pointing to a valid memory location.

On the other hand, a void pointer is a special type of pointer that can point to any data type. A void pointer is declared using the keyword void as the pointer type. A void pointer is often used when the data type of the pointed-to value is not known or when a generic pointer is needed that can point to any data type.

Since a void pointer can point to any data type, it cannot be dereferenced directly because the compiler does not know the size and data type of the pointed-to value. Therefore, to use the pointed-to value, a void pointer must first be cast to the appropriate pointer type.

8. What do you understand by the compiler in C language?
Ans: The compiler analyzes the source code to check for syntax errors, type errors, and other programming errors. If there are any errors, the compiler reports them to the developer, and the code must be corrected before it can be compiled successfully. If there are no errors, the compiler generates an object code file or executable file that can be run on the target platform. The compiler is a critical tool in the development process, as it allows developers to write code in a high-level programming language and generate efficient machine code that can be executed on various platforms. Without a compiler, developers would need to write code directly in machine language, which is much more difficult and time-consuming.

9. Explain the debugger with respect to C language.
Ans: When a program is compiled and executed, the debugger attaches to the running program and provides a user interface for developers to interact with the program. The debugger allows developers to set breakpoints in the program, which are points in the code where execution will pause so that developers can inspect the program’s state. When the program reaches a breakpoint, the debugger halts execution, and developers can inspect the values of variables, evaluate expressions, and step through the program one line at a time. The debugger also provides tools for tracing the execution of the program, identifying memory leaks and other issues, and profiling the program’s performance. Debuggers are commonly used to diagnose and fix errors in complex software applications and systems, including operating systems, database systems, and network applications.

10. What is a static identifier?
Ans: a static identifier is a variable or function that has a static storage duration. This means that the variable or function retains its value or existence throughout the entire execution of the program, rather than being created and destroyed each time the function is called or the program is executed.

A static variable declared within a function maintains its value between function calls, while a static variable declared outside of a function has a global scope and is accessible to all functions within the file in which it is declared.

Static functions are functions that are only visible within the file in which they are declared, and cannot be accessed or called from outside that file. They are often used to encapsulate implementation details and prevent name collisions with other functions.

11. Explain any three types of sorting algorithms in C language.
Ans: There are many types of sorting algorithms in C language, but I will explain three common ones:

  • Bubble Sort: Bubble Sort is a simple and easy-to-understand sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. Bubble Sort has a time complexity of O(n^2) in the worst case, making it inefficient for large data sets.
  • Quick Sort: Quick Sort is a popular and efficient sorting algorithm that works by partitioning an array into two sub-arrays, according to a pivot element, and recursively sorting the sub-arrays. The partitioning is done in such a way that all the elements smaller than the pivot are placed to the left of the pivot, and all the elements larger than the pivot are placed to the right of the pivot. Quick Sort has a time complexity of O(n log n) in the average case, but can have a worst-case time complexity of O(n^2) if the pivot is not chosen correctly.
  • Merge Sort: Merge Sort is a divide-and-conquer sorting algorithm that works by dividing an array into two halves, recursively sorting each half, and merging the sorted halves back together. The merging process involves comparing the elements from each half and placing them in order in a new array. Merge Sort has a time complexity of O(n log n) in the worst case, making it efficient for large data sets.

Each of these sorting algorithms has its own strengths and weaknesses, and the choice of which one to use depends on the specific requirements of the problem being solved.

12. Explain memory management in C language.
Ans: In C language, memory is allocated dynamically using functions such as malloc(), calloc(), and realloc(). These functions allow the programmer to request a specific amount of memory from the system and assign it to a variable or data structure. The memory allocated by these functions is stored in the heap, which is a region of memory that is separate from the stack and is managed by the operating system.

The programmer is responsible for deallocating the memory when it is no longer needed, using the free() function. Failure to deallocate memory can lead to memory leaks, which can cause the program to run out of memory and crash.

Memory management in C language also involves managing the stack, which is a region of memory used to store variables and function calls. The stack is managed by the compiler and is used to keep track of function calls and their local variables. When a function is called, a new frame is created on the stack to store its local variables and other information, and when the function returns, the frame is removed from the stack.

13. Explain dynamic binding in C language.
Ans: Dynamic binding is a mechanism in C language that permits a program to identify the method or function to call during runtime, rather than during compilation, and is also known as late or runtime binding. Pointers to functions are used to implement dynamic binding, which obtain a value during runtime based on the object type they are pointing to. This mechanism is especially beneficial when dealing with polymorphic objects where the object type is not known until runtime. It enables the program to call the appropriate function based on the object’s actual type instead of its declared type.

Virtual functions are key to dynamic binding and are functions that can be overridden by derived classes and declared in a base class. The program uses a virtual function table, also called a vtable or virtual method table, to determine which function to call based on the object’s actual type when a virtual function is invoked on an object. Pointers to functions can be utilized to implement dynamic binding, where they acquire a value during runtime based on the actual type of the object. In essence, dynamic binding is a potent mechanism in C language that enables a program to determine the method or function to call during runtime based on the actual type of the object.

It is advantageous when working with polymorphic objects and is implemented using virtual functions and pointers to functions.

14. What is the malloc function in C language?
Ans: malloc() is a function in C language that stands for "memory allocation". It is used to dynamically allocate a block of memory of a specified size at runtime. The malloc() function takes an argument representing the size of the memory block to be allocated and returns a pointer to the first byte of the block. This dynamically allocated memory can be used to store data that needs to be created and destroyed during runtime, such as arrays, structures, or strings.

It is important to note that the memory allocated by malloc() is not initialized to any specific value, so it may contain garbage data. It is the programmer’s responsibility to initialize the memory before using it. Additionally, the memory must be explicitly freed by the program using the free() function when it is no longer needed to avoid memory leaks. If malloc() fails to allocate the requested memory block, it returns a NULL pointer.

15. Explain global variables in C.
Ans: A global variable is a variable that is declared outside any function and can be accessed by any function or code block in the program.

Global variables have a global scope, which means they are visible throughout the program and their value can be modified by any function that has access to them. Global variables can be initialized with an initial value, but if not initialized, they will be assigned a default value of 0.

To declare a global variable, it should be declared outside any function, typically at the top of the source file, before the main() function.

It is important to use global variables with caution, as they can be accessed and modified by any function in the program, which can lead to unexpected behavior if not used carefully. Global variables can also increase the complexity of the program and make it harder to maintain, so it is generally recommended to use them sparingly.

Accenture C language Questions : Coding

In accenture interview rounds you might be asked various coding questions in the language of your preference so here we wll go through the coding questions in C language during aceceture interview.

Q1. Given a string you have to reverse the words of the string.

Sample Input

s = “i love programming very much” 

Sample Output

s = “much very programming love i” 

Ans.

#include <stdio.h>

void reverse(char* begin, char* end)
{
    char temp;
    while (begin < end) {
        temp = *begin;
        *begin++ = *end;
        *end-- = temp;
    }
}

void reverseWords(char* s)
{
    char* word_begin = s;

    char* temp = s;

    while (*temp) {
        temp++;
        if (*temp == '\0') {
            reverse(word_begin, temp - 1);
        }
        else if (*temp == ' ') {
            reverse(word_begin, temp - 1);
            word_begin = temp + 1;
        }
    }

    reverse(s, temp - 1);
}

int main()
{
    char s[] = "i like programming very much";
    char* temp = s;

    reverseWords(s);
    printf("%s", s);
    return 0;
}

Output

much very programming like i

Q2. Given an array of N integers and a sum you have to find the number of pairs in the array that have the same sum as given in the question.

Sample Input

arr[] = {1, 5, 7, -1, 5}, sum = 6

Sample Output

3

Ans.

#include <stdio.h>

int getPairsCount(int arr[], int n, int sum)
{
    int count = 0; 

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] + arr[j] == sum)
                count++;

    return count;
}

int main()
{
    int arr[] = { 1, 5, 7, -1, 5, 1, 1, 5, 5, 3, 1 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int sum = 6;
    printf("Count of pairs is %d",
        getPairsCount(arr, n, sum));
    return 0;
}

Output

Count of pairs is 17

Q3. Given an array of N distinct elements and a number K you have to find the kth smallest element in the array.

Sample Input

arr[] = {7, 10, 4, 3, 20, 15}, K = 4 

Sample Output

10

Ans.

#include <stdio.h>
#include <stdlib.h>

int cmpfunc(const void* a, const void* b)
{
    return (*(int*)a - *(int*)b);
}


int kthSmallest(int arr[], int N, int K)
{
    qsort(arr, N, sizeof(int), cmpfunc);

    return arr[K - 1];
}

int main()
{
    int arr[] = { 122, 13, 55, 17, 49 };
    int N = sizeof(arr) / sizeof(arr[0]), K = 2;

    printf("K'th smallest element is %d",
        kthSmallest(arr, N, K));
    return 0;
}

Output

K'th smallest element is 17

Conclusion
Preparing for Accenture C language questions is essential for anyone aspiring to join Accenture or any other company that evaluates programming skills. This article has provided a compilation of important C language questions that can help you enhance your preparation and perform well in Accenture’s recruitment process. By familiarizing yourself with these questions, you can gain confidence in your C language knowledge and increase your chances of success in the interview.

Frequently Asked Questions

1. What types of questions should I expect in an Accenture interview?
The types of questions you can expect in an Accenture interview will depend on the specific role you are applying for. However, you should generally expect a mix of behavioral and technical questions. Behavioral questions will assess your soft skills and work style, while technical questions will assess your knowledge and experience in relevant areas.

2. How can I prepare for an Accenture interview?
To prepare for an Accenture interview, research the company and the specific role you are applying for. Practice answering common behavioral and technical interview questions, and be prepared to discuss your experience and skills in detail. Additionally, be sure to dress professionally, arrive on time, and be ready to ask questions about the company and the role.

3. What qualities does Accenture look for in job candidates?
Accenture looks for candidates who are adaptable, innovative, collaborative, and have strong problem-solving skills. They also value candidates who are committed to continuous learning and development, and who can work effectively in a team environment.

4. How long does the interview process typicy take at Accenture?
The length of the interview process at Accenture can vary depending on the role and the number of candidates being considered. However, it generally takes several weeks to complete the process from start to finish.

5. How can I follow up after an Accenture interview?
After an Accenture interview, it is appropriate to send a thank-you email or note to the interviewer(s) thanking them for their time and reiterating your interest in the role. You can also inquire about the next steps in the process and when you can expect to hear back from the company.

Leave a Reply

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