Qualcomm Interview Experiance
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-03-08Added By Anonymous
Source: Link
Qualcomm Interview Experiance
Round 1
Q1) Introduce yourself ?
Q2) Asked about my current role in current projects ?
Q3) Asked questions related to my current projects?
Q4) Where can we use Inter Process communication ?
Semaphores , pipes , message queues ...etc
Q5) Code a basic program using threads in c ?
wrote the following program
```
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#include <stdlib.h>
struct s_strct{
int num;
int sumeven;
int sumodd;
int arr[100];
};
void* thread_code1(void *s){
struct s_strct *s2 = (struct s_strct*)s;
int a = (int)s2->num;
int* arr = (int *)s2->arr;
printf("in thread_code1 \n");
s2->sumeven = 0;
for(int i=0;i<a;++i){
if(arr[i]%2==0){
s2->sumeven += arr[i];
}
}
}
void* thread_code2(void *s){
struct s_strct *s2 = (struct s_strct*)s;
int a = (int)s2->num;
int* arr = (int *)s2->arr;
printf("in thread_code2 \n");
s2->sumodd = 0;
for(int i=0;i<a;++i){
if(arr[i]%2==1){
s2->sumodd += arr[i];
}
}
}
int main()
{
pthread_t tid1,tid2;
int n;
struct s_strct * s;
s = malloc(sizeof(struct s_strct));
printf("enter tot num \n");
scanf("%d",&n);
s->num = n;
printf("enter nums \n");
for (int i = 0; i < n; ++i)
{
scanf("%d",&(s->arr[i]));
}
pthread_create(&tid1,0,&thread_code1,(void *)s);
pthread_create(&tid2,0,&thread_code2,(void *)s);
pthread_join(tid1,0); // wait for thread to complete
pthread_join(tid2,0);
printf("in main \n");
printf("sum odd is = %d\n",s->sumodd );
printf("sum even is = %d\n",s->sumeven );
}
```
run using
$gcc evenodd.c -lpthread
$./a.out
Q6) Code a program to toggle 3 rd bit from right side of a decimal number ?
```
#include <iostream>
using namespace std;
int toggle_3rd_bit(int num) {
// Create a mask with the 3rd bit set to 1 using left shift operator.
int mask = 1 << 2;
// Toggle the 3rd bit using the bitwise XOR operator.
return num ^ mask;
}
int main() {
int number;
cout << "Enter a decimal number: ";
cin >> number;
int toggled_number = toggle_3rd_bit(number);
cout << "Original number: " << number << endl;
cout << "Toggled number: " << toggled_number << endl;
return 0;
}
```
Q7) Code a simple program using semaphores?
{was not able to complete this}
```
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#define SZ 10
#define loop 20
int buf[SZ],f,r;
sem_t full,mutex,empty;
void *produce(void *arg){
int i;
for (int i = 0; i < loop; ++i)
{
sem_wait(&empty);
sem_wait(&mutex);
printf("produced item is %d \n", i);
buf[(++r)%SZ]=i;
sleep(1);
sem_post(&mutex);
sem_post(&full);
int value;
sem_getvalue(&full, &value);
printf("full %d\n",value);
// int value2;
// sem_getvalue(&mutex, &value2);
// printf("mutex %d\n",value2);
// printf("full %ld\n", full);
}
}
void *consume(void *arg){
int i,item;
for (int i = 0; i < loop; ++i)
{
sem_wait(&full);
sem_wait(&mutex);
int value;
sem_getvalue(&full, &value);
printf("full %d\n",value);
// printf("full %ld\n", full);
item=buf[(++f)%SZ];
printf("consumed item is %d \n", item);
sleep(1);
sem_post(&mutex);
sem_post(&empty);
}
}
int main(){
pthread_t tid1,tid2;
sem_init(&mutex,0,1);
sem_init(&full,0,1);
sem_init(&empty,0,SZ);
pthread_create(&tid1,NULL,produce,NULL);
pthread_create(&tid2,NULL,consume,NULL);
pthread_join(tid1,NULL);
pthread_join(tid1,NULL);
}
```
Q8) Code a program using TCP uplink?
was not able to code this , socket programming was required
Q6) Code a program to toggle 3 rd bit from right side of a decimal number ?
```
#include <iostream>
using namespace std;
int toggle_3rd_bit(int num) {
// Create a mask with the 3rd bit set to 1 using left shift operator.
int mask = 1 << 2;
// Toggle the 3rd bit using the bitwise XOR operator.
return num ^ mask;
}
int main() {
int number;
cout << "Enter a decimal number: ";
cin >> number;
int toggled_number = toggle_3rd_bit(number);
cout << "Original number: " << number << endl;
cout << "Toggled number: " << toggled_number << endl;
return 0;
}
```
Q7) Code a simple program using semaphores?
{was not able to complete this}
```
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#define SZ 10
#define loop 20
int buf[SZ],f,r;
sem_t full,mutex,empty;
void *produce(void *arg){
int i;
for (int i = 0; i < loop; ++i)
{
sem_wait(&empty);
sem_wait(&mutex);
printf("produced item is %d \n", i);
buf[(++r)%SZ]=i;
sleep(1);
sem_post(&mutex);
sem_post(&full);
int value;
sem_getvalue(&full, &value);
printf("full %d\n",value);
// int value2;
// sem_getvalue(&mutex, &value2);
// printf("mutex %d\n",value2);
// printf("full %ld\n", full);
}
}
void *consume(void *arg){
int i,item;
for (int i = 0; i < loop; ++i)
{
sem_wait(&full);
sem_wait(&mutex);
int value;
sem_getvalue(&full, &value);
printf("full %d\n",value);
// printf("full %ld\n", full);
item=buf[(++f)%SZ];
printf("consumed item is %d \n", item);
sleep(1);
sem_post(&mutex);
sem_post(&empty);
}
}
int main(){
pthread_t tid1,tid2;
sem_init(&mutex,0,1);
sem_init(&full,0,1);
sem_init(&empty,0,SZ);
pthread_create(&tid1,NULL,produce,NULL);
pthread_create(&tid2,NULL,consume,NULL);
pthread_join(tid1,NULL);
pthread_join(tid1,NULL);
}
```
Q8) Code a program using TCP uplink?
was not able to code this , socket programming was required