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!

Wipro C Language Questions

Last Updated on February 21, 2023 by Prepbytes

Wipro is an India-based company that is famous for providing its services of consulting, IT services, and business to clients and it has clients from all around the world.
Wipro is among the top choices of students to get into because of its reputation and other benefits like a good working environment, and competitive salary, the growth one gets here is very helpful for future progress, and the global exposure that Wipro provides gives it an edge over various companies.
But to get into Wipro you have to clear certain tests and interviews and in those interviews, you might be asked questions in various languages and c is one of the most asked languages in interviews so here we will discuss the Wipro c language questions.

Wipro C Language Questions: Technical

The questions on C language will be asked in two parts one that will focus on the technical domain and the other will focus on the coding domain. Here we will discuss the questions on a technical domain.

Q1. What is a static function in C language?
Ans: In C programming language, a static function is a function that has its scope limited to the file in which it is defined. This means that the function can only be accessed and called within the same file it was defined in and cannot be used by any other files or programs.

The keyword "static" is used to declare a function as static, and it is placed before the function’s return type.
The function is only visible within the file it is defined in, which means that its name is not exported to the symbol table of the linker. This can be useful for preventing naming conflicts between functions in different files.

In summary, a static function in C is a function that has its scope limited to the file in which it is defined, and cannot be accessed by other files or programs.

Q2. What are the advantages and disadvantages of using unions in C languages?
Ans: In C programming language, unions are a data structure that allows multiple variables to be stored in the same memory location. Here are some advantages and disadvantages of using unions:

Advantages:
The advantages of using unions in c are:

  • Memory efficiency: Unions can save memory by allowing multiple variables to share the same memory location. This can be especially useful when working with embedded systems or other memory-constrained environments.
  • Type casting: Unions allow for easy type casting of one variable to another. This can be useful in situations where you need to convert one data type to another without having to allocate additional memory.
  • Access to multiple data types: Unions can be used to store different types of data in the same memory location. This can be useful when dealing with multiple data types that are related in some way, such as different representations of the same data.

Disadvantages:
The disadvantages of using unions in C are:

  • Type safety: Unions can be less type-safe than other data structures because they allow for multiple types to be stored in the same memory location. This can make it more difficult to write code that is free from type errors and other bugs.
  • Uninitialized memory: Because unions can hold multiple types of data, it can be easy to accidentally read uninitialized memory or write to memory that has already been freed. This can lead to hard-to-debug bugs and security vulnerabilities.
  • Portability: The behavior of unions is not well-defined in some situations, which can lead to portability issues when moving code between different platforms or compilers.

Q3. What is a huge pointer in C language?
Ans: In the C programming language, there is no data type called "huge pointer." However, in older versions of C, there was a data type called "huge" that was used to denote pointers that pointed to data in extended memory beyond the limits of the standard 64 KB memory model.

The "huge" data type was primarily used in older MS-DOS environments where the memory model was limited. It was used to allocate and manage large memory blocks that could not fit into the standard memory model. A "huge" pointer was a pointer that pointed to such large memory blocks.

Q4. Explain the use of void pointer in C?
Ans: In the C programming language, a void pointer (also called a generic pointer) is a pointer that has no associated data type. It is a special type of pointer that can be used to hold a pointer to any data type and can be converted to and from any other pointer type. The void pointer is declared using the "void" keyword

Q5. Explain the constants with respect to C language.
Ans: In the C programming language, a constant is a value that cannot be changed during the execution of the program. Constants are used to represent fixed values in a program, such as numerical values, character strings, or memory addresses.

There are two types of constants in C:

  1. Literal constants: These are values that are directly written into the program code. For example:

    • Integer constants
    • Floating-point constants
    • Character constants
    • String constants
  2. Symbolic constants: These are defined using the #define preprocessor directive, and are used to define a constant value that can be referenced throughout the program.

Constants in C are often used to define values that should not be changed during the execution of the program, such as mathematical constants or fixed-size data structures. Using constants instead of variables can help to make the program more readable, maintainable, and less prone to errors. Additionally, using symbolic constants instead of literal constants can help to improve the readability and maintainability of the code, as well as make it easier to modify the program in the future.

Q6. What is the purpose or use of the main() function in C?
Ans: The main() function is the entry point for C programs and serves as the starting point for program execution. It is mandatory in every C program and is responsible for controlling the flow of the program. The code inside the main() function can accept input, process data, output results, and call other functions or libraries to perform complex tasks. The main() function is required to return an integer value, typically 0, to indicate the successful completion of the program. The code inside the main() function determines the behavior of the program and how it interacts with the user and the environment.

Q7. What is dynamic binding?
Ans: In the C programming language, dynamic binding refers to the process of resolving function calls at runtime, rather than at compile time. This allows a program to call functions whose names are not known until the program is executed, or to call functions that are defined in shared libraries that are loaded dynamically at runtime.

Dynamic binding is typically achieved using function pointers, which are variables that store the address of a function. Function pointers can be assigned to different functions at runtime, allowing the program to dynamically choose which function to call based on the context of the program.

Dynamic binding is used in many programming paradigms, such as object-oriented programming and functional programming, to provide a flexible and extensible programming model. For example, in object-oriented programming, dynamic binding is used to implement polymorphism, which allows objects of different types to be treated in a uniform way.

Q8. What is a dynamic constructor?
Ans: In C, there is no concept of a dynamic constructor. Constructors are typically associated with object-oriented programming languages, such as C++. In C, memory allocation and initialization are typically done separately using functions such as malloc() and calloc(), which allocate memory dynamically at runtime, and memset() and memcpy(), which initialize memory to a given value.

In some cases, a C program may simulate a constructor-like behavior by defining a function that allocates memory, initializes it to a default value, and returns a pointer to the initialized memory. This can be useful for creating complex data structures, such as linked lists or trees, where each node needs to be initialized with default values before it can be used.

Q9. What is the difference between malloc and new?
Ans: malloc and new are both used to dynamically allocate memory in C++.

  • Malloc: malloc is a function from the C standard library, which allocates a block of memory of a given size and returns a pointer to the beginning of that block. It takes a single argument, the number of bytes to allocate, and returns a void pointer (void *), which must be explicitly cast to the appropriate pointer type. malloc does not initialize the memory it allocates, so the contents of the memory are undefined until explicitly initialized.
  • New: new is a keyword in C++, used to allocate memory and construct objects. Unlike malloc, new not only allocates memory but also initializes it by calling the constructor of the object being allocated. new can also be used to allocate arrays of objects, which can be dynamically resized using the delete[] operator.

In addition, new automatically performs the necessary type conversions and allows the use of operator overloading to customize the allocation and initialization of objects. Another significant difference between new and malloc is that new throws an exception when it fails to allocate memory, while malloc returns a null pointer.

Q10. What is the difference between strcpy and strdup?
Ans: strcpy and strdup are both functions in the C standard library that deal with strings.

Strcpy: strcpy is a function that copies a string from one location to another. It takes two arguments, the destination string and the source string. The destination string must be a character array with enough space to hold the contents of the source string. strcpy copies the characters from the source string to the destination string until it encounters a null character, which marks the end of the string. strcpy does not allocate memory, so the destination string must be pre-allocated.

Strdup: strdup is a function that duplicates a string by dynamically allocating memory for a new string and copying the contents of the source string to it. The strdup function takes a single argument, the source string, and returns a pointer to the new duplicated string. The strdup function automatically allocates memory for the new string, so the caller does not need to pre-allocate any memory. The caller is responsible for freeing the memory allocated by strdup using the free function.

One important difference between strcpy and strdup is that strcpy requires the caller to pre-allocate memory for the destination string, while strdup automatically allocates memory for the new string. This makes strdup more convenient to use in some cases, but also requires the caller to free the memory allocated by strdup. Another difference is that strdup returns a pointer to the new duplicated string, while strcpy does not return a value.

Q11. What are macros?
Ans: In computer programming, macros are a way to automate repetitive or complex tasks by defining a sequence of instructions that can be reused multiple times. A macro is essentially a small program that is defined and invoked within a larger program.

Macros can take input parameters, and can generate output or side effects when invoked. They are typically defined using a special syntax or language specific to the programming language or tool that is being used.

In many programming languages, macros are preprocessed before the actual program is compiled or interpreted, and the resulting code may include the expanded code generated by the macros. This can help reduce code duplication and improve the maintainability of large software projects.

Q12. Where are auto variables stored?
Ans: Auto variables, also known as automatic variables, are local variables in a function or block that are declared using the "auto" keyword (which is optional in most programming languages). These variables are created when the function or block is entered, and are automatically destroyed when the function or block is exited.

The memory for auto variables is typically allocated on the stack, which is a region of memory that is managed automatically by the program’s runtime system. The stack is a contiguous block of memory that is used to store local variables and function call frames in a last-in-first-out (LIFO) order.

Q13. What is the issue with runtime type identification?
Ans: Runtime type identification (RTTI) is a feature in many programming languages that allows programs to determine the type of an object or variable at runtime. While this feature can be useful in certain cases, there are several issues with RTTI that can make it problematic in some contexts:

  • Performance Overhead: The process of determining the type of an object at runtime can be time-consuming, especially for complex object hierarchies. This can result in significant performance overhead, which can be a problem for real-time or high-performance applications.
  • Security Risks: RTTI can also introduce security risks in certain situations, especially in systems where untrusted code is executed. If an attacker can trick a program into performing an operation on an object of the wrong type, this can lead to memory corruption or other security vulnerabilities.
  • Object Layout Dependencies: Programs that use RTTI are often tightly coupled to the layout of objects in memory, which can make them less portable and more difficult to maintain. Changes to the layout of objects can break RTTI-based code, which can make it difficult to upgrade or modify software over time.

Q14. What is a conversion operator?
Ans: unction in C++ that allows a class to define how objects of that class can be converted to other data types.

When a conversion operator is defined, an object of the class can be used in contexts where a different type is expected, and the compiler will automatically convert the object to the appropriate type using the conversion operator.

Conversion operators are defined using the keyword "operator" followed by the target type and must be member functions of the class

Q15. What are the pointer address and values?
Ans: In computer programming, a pointer is a variable that stores the memory address of another variable. The memory address is a unique identifier that corresponds to the location in the memory where the variable is stored. Pointers allow programs to manipulate and access variables indirectly, by using their memory addresses.

In C and C++ programming languages, pointers are declared using the symbol. Once a pointer is declared, it can be assigned the memory address of another variable using the & operator. a pointer variable stores the memory address of another variable, and the operator can be used to access the value of the variable indirectly through the pointer.

Wipro C language Questions: Coding

The coding questions are one of the deciding factors in the selection of candidates as this will show the way of thinking of the candidate.

Q1. Given an array of n distinct elements return the element if the value of the element in the array is equal to the corresponding index else return -1.

Sample Input

arr[] = {-10, -5, 0, 3, 7}

Sample Output

3  // arr[3] == 3 

Ans.

#include <stdio.h>

int linearSearch(int arr[], int n)
{
    int i;
    for (i = 0; i < n; i++) {
        if (arr[i] == i)
            return i;
    }

    return -1;
}

int main()
{
    int arr[] = { -100, -10, 0, 81, 4, 121, 310, 9, 10 };
    int n = sizeof(arr) / sizeof(arr[0]);
    printf("Fixed Point is %d", linearSearch(arr, n));
    getchar();
    return 0;
}

Output

Fixed Point is 4

Q2. Given a number find the factorial of the given number.

Sample Input

5

Sample Output

120

Ans.

#include <stdio.h>

unsigned int factorial(unsigned int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}

int main()
{
    int num = 10;
    printf("Factorial of %d is %d", num, factorial(num));
    return 0;
}

Output

Factorial of 10 is 3628800

Q3. Given an element of n size print the alternate element of the given array.

Sample Input

arr[] = {1, 2, 3, 4, 5}

Sample Output

1 3 5

Ans.

#include <stdio.h>


void printAlter(int arr[], int N)
{

    for (int currIndex = 0;
        currIndex < N; currIndex++) {

    
        if (currIndex % 2 == 0) {
            printf("%d ", arr[currIndex]);
        }
    }
}

int main()
{
    int arr[] = { 11, 21, 35, 44, 25, 85,64 };
    int N = sizeof(arr) / sizeof(arr[0]);
    printAlter(arr, N);
}

Output

11 35 25 64

Q4. Write a program to find whether the given number is an Armstrong number or not?

Sample Input

153

Sample Output

Yes

Ans.

#include <stdio.h>

int power(int x, unsigned int y)
{
    if (y == 0)
        return 1;
    if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    return x * power(x, y / 2) * power(x, y / 2);
}

int order(int x)
{
    int n = 0;
    while (x) {
        n++;
        x = x / 10;
    }
    return n;
}
int isArmstrong(int x)
{
    int n = order(x);
    int temp = x, sum = 0;
    while (temp) {
        int r = temp % 10;
        sum += power(r, n);
        temp = temp / 10;
    }

    if (sum == x)
        return 1;
    else
        return 0;
}

int main()
{
    int x = 153;
    if (isArmstrong(x) == 1)
        printf("True\n");
    else
        printf("False\n");

    x = 1253;
    if (isArmstrong(x) == 1)
        printf("True\n");
    else
        printf("False\n");

    return 0;
}

Output

True
False

Q5. Given the number in decimal representation that contains only one set bit in its binary representation then find the position of that set bit. If there are multiple set bits then return -1.

Sample Input

N = 5

Sample Output

-1

Ans.

#include <stdio.h>


int isPowerOfTwo(unsigned n)
{
    return n && (!(n & (n - 1)));
}

int findPosition(unsigned n)
{
    if (!isPowerOfTwo(n))
        return -1;

    unsigned i = 1, pos = 1;

    
    while (!(i & n)) {
        i = i << 1;

        ++pos;
    }

    return pos;
}

int main(void)
{
    int n = 32;
    int pos = findPosition(n);
    (pos == -1) ? printf("n = %d, Invalid number\n", n) : printf("n = %d, Position %d \n", n, pos);

    n = 22;
    pos = findPosition(n);
    (pos == -1) ? printf("n = %d, Invalid number\n", n) : printf("n = %d, Position %d \n", n, pos);

    n = 1024;
    pos = findPosition(n);
    (pos == -1) ? printf("n = %d, Invalid number\n", n) : printf("n = %d, Position %d \n", n, pos);

    return 0;
}

Output

n = 32, Position 6 
n = 22, Invalid number
n = 1024, Position 11 

Frequently Asked Questions

1. What are the skills required to get a job at Wipro?
The skills required to get a job at Wipro vary depending on the job role, but generally include strong technical skills, problem-solving skills, communication skills, and a willingness to learn.

2. What is the dress code for the Wipro interview?
The dress code for the Wipro interview is typically business formal.

3. Does Wipro provide any benefits for employees?
Yes, Wipro provides benefits such as health insurance, life insurance, retirement plans, and employee discounts.

4. Does Wipro offer opportunities for career growth?
Yes, Wipro offers opportunities for career growth through training and development programs, as well as promotions.

5. What is the work-from-home policy at Wipro?
The work-from-home policy at Wipro varies depending on the job role and project, but the company has implemented remote work options during the COVID-19 pandemic.

Leave a Reply

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