Posts
 
Reputation
Joined
Last Seen
Ranked #2K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
27% Quality Score
Upvotes Received
3
Posts with Upvotes
3
Upvoting Members
3
Downvotes Received
20
Posts with Downvotes
20
Downvoting Members
3
2 Commented Posts
~7K People Reached
Favorite Forums
Favorite Tags
Member Avatar for saurabh.mehta.33234

I am trying to learn Volatile keyword in Multi Threading and I came across this statement: *Volatile is preferred in cases when one thread reads and writes a shared variable and other threads just read the same. Whereas if there are more than 2 threads performing read and write both …

Member Avatar for JamesCherrill
0
207
Member Avatar for saurabh.mehta.33234

I am trying to understand the SynchronizedMap and I ran the below code. I get the below Output with an exception. According to my understanding the exception is caused when the get() methods are trying to access the syncmap when a thread is still executing a write on the map …

Member Avatar for JamesCherrill
0
670
Member Avatar for saurabh.mehta.33234

In the below code about the synchronisation between threads, according to the output generated why is the control being transferred to the execution of the new thread despite the lock being acquired for the same object "dt" in the main method ? public class DemoThread extends Thread { public DemoThread() …

Member Avatar for JamesCherrill
0
233
Member Avatar for saurabh.mehta.33234

I am trying to run the below concurrency code: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class TestThread { public static void main(final String[] arguments) throws InterruptedException { ExecutorService executor = Executors.newSingleThreadExecutor(); try { executor.submit(new Task()); System.out.println("Shutdown executor"); executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("tasks interrupted"); } finally …

Member Avatar for JamesCherrill
0
419
Member Avatar for saurabh.mehta.33234

While referring to a particular course I came across the following code to retrieve the current day: int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); long dateTime; dateTime = dayTime.setJulianDay(julianStartDay); day = getReadableDateString(dateTime); private String getReadableDateString(long time){ SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("E MMM d"); return shortenedDateFormat.format(time); } My doubt is why are we …

Member Avatar for Taywin
0
377
Member Avatar for saurabh.mehta.33234

I am want to delete the first line of text file using RandomAccessFile class. My Input file "bulkwfids.txt" has the data as below: 234567 345578 455678 566667 Expected output needs to be(first line deleted): 345578 455678 566667 But the actual ouput I am getting is as follows: 78 56 345578 …

Member Avatar for JamesCherrill
0
1K
Member Avatar for saurabh.mehta.33234

The foll code gives o/p as 2310103 28 Now my doubt is why here 10 is printed two times although i m passing t=6 for the d parameter?? #include <stdio.h> #include <string.h> int f(int a, int b, int c,int d,int e) { printf("%d%d%d%d%d \n",a,b,c,d,e); return a+b+c+d+e; } main() { int …

Member Avatar for Unimportant
-1
244
Member Avatar for saurabh.mehta.33234

#include<stdio.h> void main() { int n=5; if(n==5?printf("Hallo"):printf("Hai"),printf("Bye")); } The output of the above code is HalloBye..But I am not able to debug it..I know that ternary has precedence over comma operator but i am stuck at which operand will go with which operator..Can someone please help

Member Avatar for Moschops
-1
236
Member Avatar for saurabh.mehta.33234

I have the following code.According to this the values of pointers p[0] and p[1] remains unchanged since the swap is made to local variables in swap function.Now my doubt is how can I swap the pointers p[0] and p[1] inside the function swap?? #include<stdio.h> int main() { char *p[2]={"hello","good morning"}; …

Member Avatar for Schol-R-LEA
-1
196
Member Avatar for saurabh.mehta.33234

#include<stdio.h> int i=5; main() { int i=6; { int i=7; printf("%d",i); } printf("%d",i); } Why does the above code doesnot give a variable redifinition error..Although the variable i is defined outside of block also??

Member Avatar for Moschops
-1
104
Member Avatar for saurabh.mehta.33234

main() { union u { struct s{int a;int b}n; struct ss{int c;long d}ni; }uu; uu.ni.c=1; uu.ni.d=0; printf("%d %d",(uu.n.a),(uu.n.b)); } output: 1 32767 Now my question is that even though I put d=0 then why does it shows 32767 as output for b?As per my knowledge union members share the same …

Member Avatar for saurabh.mehta.33234
-1
121
Member Avatar for saurabh.mehta.33234

I came across the foll code: #include<stdio.h> main() { int i=4,j=7; j=j||(printf("you can")&&(i=5)); printf("%d %d",i,j); } output: 4 1 Athough I am specifying the braces for the && operator so that it gets executed first..Then also the value of i remains 4 only..Why doesnot it gets changed to 5??Also the …

Member Avatar for Banfa
-1
229
Member Avatar for saurabh.mehta.33234

I have the following code on threads.I have a doubt that is it possible that any of the two threads created ie one and two will execute the 2nd print statement in run method before the first print statement in it?That is print hello first and then the current thread …

Member Avatar for stultuske
0
176
Member Avatar for saurabh.mehta.33234

public class HelloWorld{ static int a; public static void main(String []args){ System.out.println("Hello World"); HelloWorld h =new HelloWorld(); a = h.foo(); System.out.println(a); } int foo() { try{ throw new Exception(); } catch(Exception e){ System.out.println("catch"); return 9; } finally{System.out.println(a);return 10;} } } When I ran the above code output was: Hello World …

Member Avatar for IIM
0
161
Member Avatar for saurabh.mehta.33234

This might be a very basic question but still I am not able to figure out why is the foll code giving stackoverflow exception in main?? public class HelloWorld{ public static void main(String []args) { System.out.println("Hello World"); Animal c = new Animal(); } } class Animal { Animal e = …

Member Avatar for saurabh.mehta.33234
0
134
Member Avatar for saurabh.mehta.33234

The following code gave error on gcc compiler int main() { extern int a; printf("%d",a); return 0; } static int a=5; But when static is removed from int a then it runs with no errors..Can someone please clear the doubt??

Member Avatar for saurabh.mehta.33234
0
309
Member Avatar for saurabh.mehta.33234

the foll code when run on gcc compiler gave 12 as output `struct aa{char a:3;int b:30;char c:3;}; printf("%d",sizeof(struct aa));` but when i replace size of c to 2 then it gives 8 why is that so?? sizeof int is 4 and char is 1..

Member Avatar for nullptr
0
107
Member Avatar for saurabh.mehta.33234

Why does the following line of code generate error as " pasting / and / doesnot generate a valid preprocessing token"? Can someone please help #define comment /##/ int main() { comment printf("hello"); return 0; }

Member Avatar for deceptikon
0
161
Member Avatar for saurabh.mehta.33234

Is the sizeof operator in c a compile time or run time operator..Because the following code works fine with a gcc compiler int a; scanf("%d",&a); printf("%d",sizeof(a)); But I found in one of the tutorials thatsizeof is compile time??Can someone please clear the confusion?

Member Avatar for deceptikon
0
391
Member Avatar for saurabh.mehta.33234

What is the advantage of having few registers for CPU 1. Smaller Instruction size 2. Smaller cpu cycles 3. Smaller memory cycles 4. Increase in multiprogramming 5. None of the above. Can someone please give the answer with an explaination?

Member Avatar for saurabh.mehta.33234
0
91
Member Avatar for saurabh.mehta.33234

I read the following points related to side effects in gnu c manual it is necessary for the following points to hold true between two sequence points: 1.an object may have its stored value modified at most once by the evaluation of an expression 2.the prior value of the object …

Member Avatar for deceptikon
0
130
Member Avatar for saurabh.mehta.33234

In the book called gnu c manual I read that the following code has an undefined behavior `i=++i +1`; Because since the variable i is modified more than once between the sequence point,it is not sure that what value will 'i' have..But it is evident that the final value in …

Member Avatar for saurabh.mehta.33234
1
113
Member Avatar for saurabh.mehta.33234

how to print the foll string without using any kind of variable "How are you %dad%"

Member Avatar for Gonbe
0
152
Member Avatar for saurabh.mehta.33234

When I use void main in the code it compiles successfully but gives an runtime error on gcc compiler..But when void is replaced by int then it doesnot show any errors.What is the reason behind this behaviour?

Member Avatar for deceptikon
0
45
Member Avatar for saurabh.mehta.33234

Can anyone give a simple code to explain the statement"a funtion ca have multiple declaration but only one definition"?

Member Avatar for marc.punzirudu
0
156
Member Avatar for saurabh.mehta.33234

Why is it compulsory and necessary to initialize static variables during compile time only?

Member Avatar for marc.punzirudu
0
196
Member Avatar for saurabh.mehta.33234

The following piece of code outputs 0.1000000000001 float a=0.1; printf("%lf",a); But if I add a 10 times as long float b=0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1; printf("lf",b); It outputs as 0.999999999999989 But if a=0.1 is stored as 0.1000000000001 then the answer should be greater than 10 due to the 1 in last column.Then why is …

Member Avatar for deceptikon
0
240
Member Avatar for saurabh.mehta.33234

Why this piece of code doesnot display array contents #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]); return 0; }

Member Avatar for deceptikon
0
126
Member Avatar for saurabh.mehta.33234

Does the following code make p as a null pointer static int *p; since `printf("%u",p);` outputs as 0 though the syntax is `int *p=NULL or int *p=0`

Member Avatar for deceptikon
0
154